Easy Question - Set Variable to Another Variable Using sprintf
2 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Shashank Prasanna
on 31 Jan 2013
Edited: Shashank Prasanna
on 31 Jan 2013
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 Comments
Shashank Prasanna
on 31 Jan 2013
Here is an example that works for demonstration:
S=load('accidents.mat','datasources');
HeightMesh=S.('datasources');
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!