필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to do I set up if loop for the column size?

조회 수: 1 (최근 30일)
yc j
yc j 2016년 2월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Some of my data(say set A) is 3x1 column vector and the others(say set B) are 4x1 column vector.
each column will be used to calculate certain equations.
For example,
for set A, I'll do
A(:,1) + 10*A(:,2) + 100*A(:,3)
and for set B, i'll do
0.1*B(:,1) + B(:,2) + 10*B(:,3) + 100*B(:,4)
So I wanna make a 'if loop' to execute all the data files one by one, and let my m-file to recognize what kind of vector it's dealing with so it can use either of the above equation for right situation.
How can I make the loop?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 1일
size(TheVariable, 1)
or in your situation as you know they are vectors,
length(TheVariable)
  댓글 수: 1
Stephen23
Stephen23 2016년 2월 1일
편집: Stephen23 2016년 2월 1일
Use size and avoid using length. The length function confuses beginners so much I would suggest that it never be recommended to anyone, rather they should use size and numel. See this for an example of the a beginner very confused by length:
As Guillaume said about length: "That should be purged from every single matlab example and the function deprecated."

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by