Loading a .mat fil into my gui edit box

6 次查看(过去 30 天)
Hi
Ive made a gui with alot of editboxes, and made a save button that saves the data I've put into the edixboxes, to a .mat fil.
The mat fil is a matrix due to the many edixboxes.
But now I want to make a load button.
load(uigetfile('*.mat','Select the MATLAB code file'));
This is what I have, but it doesn't load my data into the editboxes.. What more do I need to write? I have 40 editboxes.
  1 个评论
Rabia Butt
Rabia Butt 2012-7-26
hey mikkel!
would you help me by telling how do you save the data you input in your editbox to a .mat file?????
I would appreciate your help! thanks!

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-7-3
I have to make a bunch of assumptions about how you are representing your values.
[filename pathname] = uigetfile('*.mat','Select the MATLAB code file');
L = load( fullfile( pathname, filename ) );
varnames = fieldnames(L);
fieldvals = L.(varnames{1}); %GUESS: you only have 1 variable in .mat
%GUESS: the one variable is a vector of numeric values
%GUESS: you have a vector of edit box handles
%GUESS: and each box is to get the textural representation of one value
for K = 1 : length(fieldvals)
set( YourEdithandles(K), 'String', num2str( fieldvals(K) ) );
end
  6 个评论
Mikkel
Mikkel 2012-7-7
I'm a bit lost, when you make the code general, then I don't know what to change. So the biggest help you could do for me is make it specifik for my problem. if we start from what I've made with the two matrix [3x3] and [2x2] which are called Load_soil = [3x3] and Load_dim = [2x2]
If I want to get the number 5 from the load_soil matrix into my editbox 5. What do I write?
Walter Roberson
Walter Roberson 2012-7-7
[filename pathname] = uigetfile('*.mat','Select the MATLAB code file');
L = load( fullfile( pathname, filename ) );
fieldvals = L.Load_soil;
for K = 1 : numel(fieldvals)
set( YourEdithandles(K), 'String', num2str( fieldvals(K) ) );
end

请先登录,再进行评论。

更多回答(1 个)

Mikkel
Mikkel 2012-7-7
If you wanna see the picture full its on this link: http://postimage.org/image/wxo3v3ic5/full/
I hope this image helps you understand my problem? Because I've done as you said (I think) or atleast as good as I can.
But it just gave me an error as you can see on the picture. Really hop you can help me. :)
  22 个评论
Mikkel
Mikkel 2012-7-9
编辑:Mikkel 2012-7-9
I think I understand you, but what do I type?
NaN -34 NaN NaN NaN NaN NaN NaN NaN NaN
The first line from my matrix looks like this, so if I only take that one, its a vector.
But what do I load?
YourEditHandles5 = [handles.edit1]; <--- I tryed that, but It just gave me the 1,1 = NaN and not the -34
I need something to type infront of it.
like:
YourEditHandles5 = [xxxxxxxx.xxxxxx handles.edit1];
Help
Ive tryed NaN or 0 but nothing helps, it has to be a handle
Mikkel
Mikkel 2012-7-9
This is the error I got
??? Index exceeds matrix dimensions.
Error in ==> boetten>load_Callback at 1500 set( YourEditHandles5(K), 'String', num2str( fieldvals5(K) ) );
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> boetten at 51 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)boetten('load_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by