フィルターのクリア

Easy Question - Set Variable to Another Variable Using sprintf

4 ビュー (過去 30 日間)
Ed
Ed 2013 年 1 月 31 日
I have a GUI with drop-down boxes, and based on these drop-down box values I load a specific variable (large matrix) out of my .mat file.
Here's that code which works:
STstr = get(handles.source_type,'String');
STval = get(handles.source_type,'Value');
switch STstr{STval};
case 'Single Point Source'
source_type='SingleHeightMesh';
end
SHstr = get(handles.scan_height, 'String');
SHval = get(handles.scan_height,'Value');
switch SHstr{SHval};
case '100ft'
scan_height='100';
end
filespec='%s%s';
load('MCNPdata.mat',sprintf(filespec,source_type,scan_height));
The problem is that the rest of my code uses another variable, HeightMesh which I need to assign to the large matrix I just loaded.
HeightMesh=sprintf(filespec,source_type,scan_height);
This code just assigns HeightMesh to the string value of the name of that matrix variable. How can I simply take this matrix I loaded (the name of the matrix will vary based on multiple drop-down options) and assign it to HeightMesh?
Thanks in advance.

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 31 日
編集済み: Shashank Prasanna 2013 年 1 月 31 日
S = load('MCNPdata.mat',sprintf(filespec,source_type,scan_height));
S is a structure and one of its elements will be the matrix.
HeightMesh=S.(sprintf(filespec,source_type,scan_height));
Dynamically access the matrix as above
  2 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 1 月 31 日
Here is an example that works for demonstration:
S=load('accidents.mat','datasources');
HeightMesh=S.('datasources');
Ed
Ed 2013 年 2 月 1 日
Works great - thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by