Create workspace file automatically.

Let's say I have:
a = {'one' 'two' 'three'};
b = [1 2 3];
I want each word create a file in workspace automatically and equal to number. Like:
one=1; two=2; three=3;

 Akzeptierte Antwort

Brett Shoelson
Brett Shoelson am 10 Feb. 2011

0 Stimmen

I think you mean "variable," not "file." Right?
for ii = 1:numel(a)
eval(sprintf('%s = %d',a{ii},b(ii)));
end
Cheers,
Brett

2 Kommentare

Brett Shoelson
Brett Shoelson am 10 Feb. 2011
(But I agree with Walter.) :)
faizal
faizal am 10 Feb. 2011
I accept that

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 10 Feb. 2011

0 Stimmen

This is generally considered poor programming and hard to maintain. Please see the FAQ answer on this topic for alternatives.
faizal
faizal am 10 Feb. 2011

0 Stimmen

It works. Thanks.
Yea it was 'variable' not 'file'.
Sorry

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by