Why do I recieve an error?

조회 수: 2 (최근 30일)
Axelina Lindgren
Axelina Lindgren 2021년 4월 26일
댓글: Star Strider 2021년 4월 27일
When I run the program I get the error message:
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Error in OptikVaglaraUppgift2 (line 78)
[difference minIndex(ii)] = min(diff(:,ii));
The program worked yesterday but when i opened up Matlab again it couldn't run.
Can someone please help me solve the problem and explain what is wrong?
n1 = 1; %utanför linsen
n2 = 1.5; %i linsen
D = 10; %linsens diameter (cm)
R = D./2; %linsens radie (cm)
d = 10; %fokallängd (cm)
lopt = n1*sqrt(d.^2 + R.^2); %Optiska vägen då strålen inte bryts i linsen
Y = linspace(0, R, 1000);
X = linspace(0, d, 1000);
for ii = 1:length(Y)
LoptTemp = zeros(length(Y), length(Y));
L1(:,ii) = sqrt( (d-X).^2 + Y(ii).^2)*n1;
L2(:,ii) = X*n2;
LoptTemp(:,ii) = L1(:,ii) + L2(:,ii);
diff(:,ii) = abs(LoptTemp(:,ii) - lopt);
[difference minIndex(ii)] = min(diff(:,ii));
x_fit(ii) = X(minIndex(ii));
end
figure
plot(x_fit, Y, 'black');
hold on
plot(x_fit.*-1, Y, 'black');
hold on
plot(x_fit, -Y, 'black');
hold on
plot(x_fit.*-1, -Y, 'black');
hold on
ylim([-max(Y)-3, max(Y)+3]);

답변 (2개)

Steven Lord
Steven Lord 2021년 4월 26일
Let's make sure you haven't written your own min.m function that shadows the built-in min function.
which -all min
If that doesn't resolve the problem, you wrote:
The program worked yesterday but when i opened up Matlab again it couldn't run.
What if anything changed between the last time the program worked yesterday and the first time it failed to work today? Did you install any new toolbox or add-on, did you create any new files, etc.?
  댓글 수: 1
Axelina Lindgren
Axelina Lindgren 2021년 4월 26일
I don't know if I understand how to use your code... (Pretty new to Matlab) And I can't think of anything I've changed since yesterday. I program in Eclipse with Java at the same time but it shouldn't interfere with Matlab, at least it hasn't before. It is also weird that other people can get it to work while I can't...I haven't changed any of the settings either.
I can try and write it in a new m file manually but if I just copy paste I still get the same error.

댓글을 달려면 로그인하십시오.


Axelina Lindgren
Axelina Lindgren 2021년 4월 27일
Solved it! I had a value called min in my previous code which changed the min function. To solve I simply put clear at the top of the code and now it works!
  댓글 수: 1
Star Strider
Star Strider 2021년 4월 27일
Note that clear is not the best option.
It would be best to go back and re-name the offending variable or function to something that does not overshadow any MATLAB functions, and still makes sense in the context of your code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by