Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Trouble allocating values to matrix

1 回表示 (過去 30 日間)
B T
B T 2012 年 2 月 29 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello.
I am trying to assign values to a matrix, but am having some trouble doing so.
clc;
clear all;
X=ones(22,22);
X1=3.2;
X2=1.5;
T1=X(1:3,1:3);
T2=X(10:13,9:11);
T3=X(20:22,20:21);
if T1
X*X1
else if T2
X.*X1
else if T3
X.*X1
else
X.*X2
end
end
end
end
When I do this, every value in the matrix becomes 3.2 (X1). I am not using the else statement correctly I believe.
The goal is to have the X1 values at the locations specified by T1,T2 and T3 and have everything else equal to X2.
All help greatly appreciated.
bt

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 2 月 29 日
if T1
is equivalent to
if all(T1(:))
That is, the condition is true only if every value in the matrix is non-zero.

the cyclist
the cyclist 2012 年 2 月 29 日
In addition to Walter's answer, note that in your if ... else statements, you never actually assign values to any variables. You only display X.*X1, etc.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by