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.

답변 (2개)

James Tursa
James Tursa 2014년 10월 20일

2 개 추천

Looks like a typo, missing ' in your code. Try this:
disp(['m34= ' num2str(m34(j))]);
Roger Stafford
Roger Stafford 2014년 10월 20일
편집: Roger Stafford 2014년 10월 20일

2 개 추천

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2014년 10월 20일

편집:

2014년 10월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by