필터 지우기
필터 지우기

Simple Matrix Looping Problem

조회 수: 2 (최근 30일)
B_Richardson
B_Richardson 2011년 7월 18일
Hello everyone,
I have a matrix:
B = zeros(10, 2);
B =
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
I want to fill the matrix with values in order:
%step 1 value = 15.654
B =
15.654 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
%step 2 value = 16.378
B =
15.654 16.378
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
%step 3 value = 17.478
B =
15.654 16.378
17.478 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
and so on until the matrix is full. Value is updated in a pushbutton callback. I know obviously that I have to loop through the matrix i'm just not sure of the exact syntax necessarily to step through each element in that order.
Thanks in advance!

채택된 답변

bym
bym 2011년 7월 18일
you can transpose B and then loop through and fill in values then transpose back
B = zeros(2,10)
for k = 1:20
%update value here
end
B = B.'
  댓글 수: 2
B_Richardson
B_Richardson 2011년 7월 18일
what does the last line do?
B = B.'
And I'm not familiar with the term "transpose?"
Fangjun Jiang
Fangjun Jiang 2011년 7월 18일
try this to understand it.
a=1:3
b=a'
or b=a.'

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by