Why isn't min working for me?
Mostra commenti meno recenti
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 Commento
the cyclist
il 15 Dic 2011
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?
Risposte (2)
the cyclist
il 15 Dic 2011
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 Commenti
Sarah Washington
il 15 Dic 2011
Walter Roberson
il 15 Dic 2011
clear min
Jan
il 15 Dic 2011
@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
il 15 Dic 2011
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 Commenti
Walter Roberson
il 15 Dic 2011
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
il 15 Dic 2011
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
il 15 Dic 2011
About the "clear all": http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Walter Roberson
il 15 Dic 2011
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.
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!