I'm getting an error in my function I don't understand
Mostrar comentarios más antiguos
My function is as follows
function [I,V] = MeasureResistance(R0,N,Imin,Imax,sigmaI,typeV)
if nargin < 2
N = 1;
I0 = -1 + 2*rand(N,1);
Ve = randn(N,1);
Ie = randn(N,1);
elseif nargin < 3
I0 = -1 + 2*rand(N,1);
Ve = randn(N,1);
Ie = randn(N,1);
elseif nargin < 7
I0 = Imin + (Imax - Imin)*rand(N,100000);
Ie = sigmaI;
if typeV == 'N'
Ve = randn(N,1);
elseif typeV == 'U'
Ve = rand(N,1);
end
end
V0 = R0*I0;
I = I0 + Ie;
V = V0 + Ve;
However when I run the function I get this error
Error: File: MeasureResistance.m Line: 18 Column: 17 The expression to the left of the equals sign is not a valid target for an assignment.
Any insight as to what may be causing this?
2 comentarios
Image Analyst
el 14 de Oct. de 2014
Like almost all other people, you didn't copy the full error message - all the red text. You just snipped out a part and left out the crucial part of what line 18 is. What is line 18? The error message will tell you. Is it
Ve = rand(N,1);
because that's what I get when I count down your code. If so, there's nothing wrong with that line.
Obsidian
el 14 de Oct. de 2014
Editada: per isakson
el 14 de Oct. de 2014
Respuesta aceptada
Más respuestas (1)
Guillaume
el 14 de Oct. de 2014
The best way for you to find out what is going wrong is to type:
dbstop if error
at the command line before calling your function. When the error occurs, it will go into debug mode and you can inspect V0 and Ve to see what their size is.
Additionally, you could also set a breakpoint at the start of your function and then step through your code line by line to see where it is going wrong.
Categorías
Más información sobre Multidimensional Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!