Hot to display a variable from a row ?
Show older comments
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.
Answers (2)
James Tursa
on 20 Oct 2014
Looks like a typo, missing ' in your code. Try this:
disp(['m34= ' num2str(m34(j))]);
Roger Stafford
on 20 Oct 2014
Edited: Roger Stafford
on 20 Oct 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 ....
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!