GUIDE user input to plot data

1 visualización (últimos 30 días)
B_Richardson
B_Richardson el 6 de Jul. de 2011
Respondida: Image Analyst el 27 de Dic. de 2021
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

Respuestas (2)

Voss
Voss el 27 de Dic. de 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.

Image Analyst
Image Analyst el 27 de Dic. de 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)
results =
results(:,:,1) = 2 3 5 2 2 9 4 5 6 results(:,:,2) = 9 5 8 4 7 4 2 7 2 results(:,:,3) = 8 3 9 4 4 1 6 2 4
s2 = results(1, :, 1:3) % Still a 3-D array.
s2 =
s2(:,:,1) = 2 3 5 s2(:,:,2) = 9 5 8 s2(:,:,3) = 8 3 9
To get a 2-D slice from results you can do:
s2 = squeeze(results(1, :, 1:3)) % Now s2 is a 2-D array.
s2 = 3×3
2 9 8 3 5 3 5 8 9
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().

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by