Why isn't min working for me?
이전 댓글 표시
I have been trying the examples from the documentation but those don't even work. I keep getting the error that index exceeds matrix dimensions. Does anyone know what I should do?
댓글 수: 1
the cyclist
2011년 12월 15일
It is pretty difficult to diagnose your problem when you don't provide any code. Can you edit your question to include a small snippet that gives the error?
답변 (2개)
the cyclist
2011년 12월 15일
Did you accidentally define a variable called "min", and it is now being used as a variable rather than a function? For example:
min = 0; % Bad coding! Don't use keyword as variable name!
min([6 3])
will give such an error.
댓글 수: 3
Sarah Washington
2011년 12월 15일
Walter Roberson
2011년 12월 15일
clear min
Jan
2011년 12월 15일
@the cyclist: Small correction: "min" is not a _keyword_, but a toolbox function. See "help iskeyword" and "edit iskeyword". But the argument is correct inspite of this term. +1
Avishek
2011년 12월 15일
be sure to use this lines of codes in all script files that u write
clear all% to clear all the variables
clc; % clear command
*suppose *
a= [1 2 3 4 5 6 7];
min_a=min(a);
% if b is a matrix
b=[1 2 3 4; 2 3 4 5;]
min_b= min(b(:));
% b(:) this command transforms b into a vector from a matrix
댓글 수: 4
Walter Roberson
2011년 12월 15일
No no no, do *not* use 'clear all' unless you are _very_ proficient in MATLAB! 'clear all' can cause a large number of subtle problems :(
Avishek
2011년 12월 15일
whenever you are writing anew script file , its necessary to use clear all.
otherwise it may cause a lot of problems , if u dont use it.
moreover if you are working on image processing it contains large no of datas, then all the variables in the workspace will be using a lot of memory. the system can go out of memory.
Chandra Kurniawan
2011년 12월 15일
About the "clear all": http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Walter Roberson
2011년 12월 15일
Avishek, you are using "clear all" without understanding what it does. Once you know what it really does, you will likely find that good uses for it are quite rare.
If you are calling a script file from the command line or from a script file, then chances are that you have created some variables already that you do not want to erase.
If you are calling a script file from a function, if you have "clear all" then everything in the function workspace (and much more!) will be deleted, which is going to cause problems for the function.
Using "clear all" from a script makes your script unusable as a utility routine to do some work, discouraging the important practice of code re-use.
With regards to space issues: when you are writing a script or function that uses variables of more than trivial size, you should get in the habit of "clear" of the individual variables once your code is finished with them.
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!