questions on assigning values from a vector

Hi all,
I am trying to do this assignment:
x1=x(1);
x2=x(2);
.
.
xN=x(N);
How could I do it using a for loop so that I don't need to write them down explicitly. Thanks.

 採用された回答

Wayne King
Wayne King 2013 年 12 月 10 日
編集済み: Wayne King 2013 年 12 月 10 日

1 投票

x = randn(10,1);
for nn = 1:10
eval(['x' int2str(nn),' = x(nn);']);
end
But eval() is pretty inefficient, so are you sure you want to do this. Anyway, you'll see that if you execute the above you will have variables x1, x2, ... x10 in your workspace

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2013 年 12 月 10 日
編集済み: Sean de Wolski 2013 年 12 月 10 日

1 投票

This is generally recommended against as it is much easier (not to mention faster) to manipulate a 1xn vector x than dealing with n scalar arrays.

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

質問済み:

2013 年 12 月 10 日

編集済み:

2013 年 12 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by