I'm getting an error in my function I don't understand
古いコメントを表示
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 件のコメント
Image Analyst
2014 年 10 月 14 日
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
2014 年 10 月 14 日
編集済み: per isakson
2014 年 10 月 14 日
採用された回答
その他の回答 (1 件)
Guillaume
2014 年 10 月 14 日
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.
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!