GUI load file.mat and use it

Hi,
I am creating a GUI and need to use data from m.file. It's working for the first file, but not or the second. Both are (double). Any idea?
matrice_losses.mat is load, but not MM...
Regards

5 comentarios

Adam
Adam el 23 de En. de 2020
What happens? Nothing? An error? Incorrect results? If you get an error please post the error message.
MartinM
MartinM el 23 de En. de 2020
Sorry I forget it
Error using load
Attempt to add "mm" to a static workspace.
See Variables in Nested and Anonymous Functions.
Error in GUI_Code/PushB (line XX)
load MM;
Error while evaluating UIControl Callback.
mm is the name on the variable wich should be used
Adam
Adam el 24 de En. de 2020
Given that error I'm surprised the first matfile loads. A nested function does give you this static workspace that you can't add variables to, as far as I am aware (certainly when I put breakpoints in these files and try to create variables on command line I can't). If you don't use nested functions that particular error would go away, but again, I don't really understand how it doesn't also give that error for your first file, without running the code.
Jakob B. Nielsen
Jakob B. Nielsen el 24 de En. de 2020
It is possible that you can load matrice_losses because you subsequently "do something" to it, either inside your function or elsewhere in the code. That means it is a nested variable within your GUI workspace (I dont know the correct terms, sorry ;)
MM, however, is just loaded and done nothing with. Try initializing MM outside the function, or calling it from another function in the GUI.
I'm just spitballing here. If one thing can load, another should be able to, and this is the only difference I can see out of what you posted.
Stephen23
Stephen23 el 24 de En. de 2020
Bad code practices strike again!
You can easily avoid this error by loading into an output variable (which you should be doing anyway), e.g.:
S = load('matrice_losses.mat');
lamfit = S.matrice_losses(:,1).*1e-3;
lossdB = S.matrice_losses(:,2);

Iniciar sesión para comentar.

 Respuesta aceptada

Jose Jeremias Caballero
Jose Jeremias Caballero el 24 de En. de 2020
Editada: Jose Jeremias Caballero el 24 de En. de 2020

0 votos

function PushB(hObject,eventdata,handles)
load matrice_losses
lamfit=(matrice_losses(:,1).*1e-3)
lossdB =matrice_losses(:,2);
u=load('MM.mat')
mm=u.mm
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 23 de En. de 2020

Comentada:

el 24 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by