필터 지우기
필터 지우기

Loading a .mat fil into my gui edit box

조회 수: 6 (최근 30일)
Mikkel
Mikkel 2012년 7월 3일
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