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.

Antworten (2)

James Tursa
James Tursa am 20 Okt. 2014

2 Stimmen

Looks like a typo, missing ' in your code. Try this:
disp(['m34= ' num2str(m34(j))]);
Roger Stafford
Roger Stafford am 20 Okt. 2014
Bearbeitet: Roger Stafford am 20 Okt. 2014

2 Stimmen

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 ....

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 20 Okt. 2014

Bearbeitet:

am 20 Okt. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by