Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Subscripted assignment dimension mismatch using text value
1 回表示 (過去 30 日間)
古いコメントを表示
I have a vector u(1,1) = 6 and a vector delta_hat = [1,2,3,4,5,6]'
I have tried to create a function so that when the value is even it will populate the existing element with 'X_naught' and if odd populate 'Y_naught':
for i = 1:u(1,1)
if mod(delta_hat(i,1),2) == 0
delta_hat(i,1) = 'X_naught'
%number is even
else
delta_hat(i,1) = 'Y_naught'
%number is odd
end
end
Why am I getting the above error?
0 件のコメント
回答 (2 件)
Image Analyst
2014 年 10 月 18 日
You need to use a cell array instead of a regular numerical array because you'll be mixing numbers and strings. Read about cell arrays here:
0 件のコメント
Star Strider
2014 年 10 月 18 日
Your original ‘delta_hat’ is defined as a (1x6) double vector. You need to define a new array (I called it ‘delta_str’ here), and adding a dimension to ‘delta_str’ to accommodate the length.
With those few modifications, it works:
u(1,1) = 6;
delta_hat = [1,2,3,4,5,6];
for i = 1:u(1,1)
if mod(delta_hat(i),2) == 0
delta_str(i,:) = 'X_naught';
%number is even
else
delta_str(i,:) = 'Y_naught';
%number is odd
end
end
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!