フィルターのクリア

Using multiple strings to name a variable

4 ビュー (過去 30 日間)
wefoust
wefoust 2012 年 11 月 29 日
Hello, I have list of string variables, and I would like to use them to name an array. For example, my string variables are as followed:
"model='GFDL'"
"forcing='rcp45'"
"time='1979_2012'".
These are meant to represent the model, the forcing scenario, and the time domain. My data is named "sea_level_pressure" and it is an array of 96x144x408. My initial thought was to use
[model forcing time]=sea_level_pressure;
I was hoping the results would yield a new variable named GFDLrcp4519792012. The purpose of this is to somewhat dynamically name my variables, because I will be working with a large dataset, and I will need to sort them by model, forcing, time, etc. However, this is not very straight forward, since I am trying to append a string to a variable. I've spent a substantial amount of time browsing the net, but no success. Any help will be greatly appreciated.
Thanks, wefoust

採用された回答

Matt Fig
Matt Fig 2012 年 11 月 29 日
編集済み: Matt Fig 2012 年 11 月 29 日
Don't do it! It is highly recommended that you do not create variables this way, as you will have no end of trouble dealing with them after wards. Instead use cell arrays or structures.
model='GFDL';
forcing='rcp45';
time='1979_2012'
S.(model).(forcing).(['t',time]) = data;
Now S is a structure.

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 11 月 29 日

wefoust
wefoust 2012 年 11 月 29 日
Wow, You guys are very fast and helpful. You answered my question as I was typing comments.
Thanks Again,
wefoust

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by