Easy Question - Set Variable to Another Variable Using sprintf

4 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by