GUIDE user input to plot data
1 view (last 30 days)
Show older comments
Hello everyone,
I have a quick question (which might also be a stupid question, forgive my ignorance in advance):
I have some data that I'm loading into my workspace from a file. The data is "result." I perform these commands on "result" in the command window.
s2 = result(1, :, 1:3);
s2 = reshape(s2, size(s2, 2),3)
I want to use "s2" in a GUI. I want to plot it like this:
function pushbutton26_Callback(hObject, eventdata, handles)
plot(handles.axes2,s2)
set(handles.axes2,'XMinorTick','on')
grid on
the end goal is to be able to allow users to select the data from the file, have those operations performed it:
s2 = result(1, :, 1:3);
s2 = reshape(s2, size(s2, 2),3);
And then plot the data. How can I do this from within my GUI? I don't expect code; just a point in the right direction would be excellent!
Thank you
0 Comments
Answers (2)
Voss
on 27 Dec 2021
You can call evalin() in your GUI callback to access variables in the base workspace:
function pushbutton26_Callback(hObject, eventdata, handles)
s2 = evalin('base','s2');
plot(handles.axes2,s2)
set(handles.axes2,'XMinorTick','on')
grid on
end
Ultimately this wouldn't be useful for users unless they have an s2 variable in their base workspace and it is what it should be. In the end, your GUI would control the file selection, loading, and calculations, and the relevant variables will be stored in the GUI's handles structure, say, rather than the base workspace.
0 Comments
Image Analyst
on 27 Dec 2021
Usually when I see : anywhere except the last index I think you need to use squeeze. Otherwise you'll still get a 3-D array, not a 2-D array like you probably thought.
results = randi(9, 3,3,3)
s2 = results(1, :, 1:3) % Still a 3-D array.
To get a 2-D slice from results you can do:
s2 = squeeze(results(1, :, 1:3)) % Now s2 is a 2-D array.
This would give a 2-D array. Like Benjamin says, if s2 is in the base workspace, you can get it into your pushbutton26_Callback() workspace by using s2 = evalin('base', 's2'), though I don't think it's a good idea to be putting and getting variables from different workspaces using tricks like using the command line, using evalin(), or using assignin().
0 Comments
See Also
Categories
Find more on Whos 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!