I'm getting an error in my function I don't understand
Show older comments
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 Comments
Image Analyst
on 14 Oct 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
on 14 Oct 2014
Edited: per isakson
on 14 Oct 2014
Accepted Answer
More Answers (1)
Guillaume
on 14 Oct 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.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!