Incorrect dimensions for raising a matrix to a power
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lea Abi nassif
il 20 Mag 2022
Modificato: Torsten
il 20 Mag 2022
Hello, i have this code that used to work on an older version of matlab but it's not on the new version and i can't seem to find the solution
PS : I'm using this code in another one
function G=gaussh(A,L,np)
% A amplitude de la gaussienne
% L largeur a mi-hauteur
% np nombre de points
x0=np/2+1;%2049;%257%256; %centre de la gaussienne =Lh/2
s=L/(2*sqrt(2*log(2))); % ecart type de la gaussienne
for x=1:1:np%512 %%
G(x)=A*exp(-(x-x0)^2/(2*(s^2)));
end
0 Commenti
Risposta accettata
Bjorn Gustavsson
il 20 Mag 2022
Just set a debug-stop in that function and check what dimensions your variables have:
dbstop in gaussh
Or just at the point where you get the error:
dbstop if error
re-run the function (step-by-step in the first case with dbstep) and check the variables with the normal means (whos, size etc).
HTH
0 Commenti
Più risposte (1)
Voss
il 20 Mag 2022
Check that your inputs to gaussh are all scalars, because it looks like all three input arguments to the function gaussh are expected to be scalars, and it works if you do that:
gaussh(1,4,10)
But if either (or both) of the second and third inputs are not scalars, you get the error you saw:
try
gaussh(1,4,[10 10])
catch e
disp(e.message);
end
try
gaussh(1,[4 4],10)
catch e
disp(e.message);
end
try
gaussh(1,[4 4],[10 10])
catch e
disp(e.message);
end
(And if the first argument is not a scalar, you get a different error:)
try
gaussh([1 1],4,10)
catch e
disp(e.message);
end
function G=gaussh(A,L,np)
% A amplitude de la gaussienne
% L largeur a mi-hauteur
% np nombre de points
x0=np/2+1;%2049;%257%256; %centre de la gaussienne =Lh/2
s=L/(2*sqrt(2*log(2))); % ecart type de la gaussienne
for x=1:1:np%512 %%
G(x)=A*exp(-(x-x0)^2/(2*(s^2)));
end
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Debugging and Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!