Hot to display a variable from a row ?

EXAMPLE
mSTAT=[1 2 3 4 5 6];
m34=[1.6 3.3 45.4 5.6 1.2 3.2];
Er=0.05;
for i=1:lenght(mSTAS)
j=1:lenght(m34)
if (m34(j)-mSTAS(i)<=Er)
disp([m34= ' num2str(m34(j))]);
end
end
The problem is that a don't know how to display just one variable from the row.

Respuestas (2)

James Tursa
James Tursa el 20 de Oct. de 2014
Looks like a typo, missing ' in your code. Try this:
disp(['m34= ' num2str(m34(j))]);
Roger Stafford
Roger Stafford el 20 de Oct. de 2014
Editada: Roger Stafford el 20 de Oct. de 2014
Writing
j=1:length(m34)
makes 'j' a vector with six elements, and therefore
m34(j)-mSTAS(i)<=Er
is a logical vector with six elements. Using it as the condition with 'if' will require that all six elements are true simultaneously for the 'if' to be satisfied. For that reason your display will never occur.
Probably you need to use nested for-loops to do what you apparently want:
for i=1:length(mSTAS)
for j = 1:length(m34)
if abs(m34(j)-mSTAS(i))<=Er
display ....

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Oct. de 2014

Editada:

el 20 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by