フィルターのクリア

How to plot a vector using a variable that contains the name of the vector.

1 回表示 (過去 30 日間)
Reynaldo
Reynaldo 2011 年 9 月 27 日
Ok here is my issue:
I have a vector called collection with some elements:
collection = [1 2 3 4 5 6 7 8 9 0];
I also have a variable called x that stores the string 'collection'
x = 'collection';
I would like to know how can I plot the values of the vector 'collection' by using the variable x that has the name of the vector stored inside it. I would like to do something like this:
plot(x)
and that the points from the vector collection get plotted. Thank you very much!!

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 27 日
You will need to use plot(eval(x)). If inside a function, use plot(evalin('base',x)).
Better way is to plan and re-organize your data structure. For example, use structure:
Data.collection=1:10;
x='collection';
plot(Data.(x))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by