이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Loading a .mat fil into my gui edit box
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
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
Walter Roberson
2012년 7월 4일
One element per edit box? One row per edit box? Or is there one variable per edit box, with each variable being 7 x 10 and you want all 70 values to appear in the edit box?
In the simplest case of one element per edit box, change length(fieldvals) to numel(fieldvals)
Mikkel
2012년 7월 4일
편집: Mikkel
2012년 7월 4일
If we make a simple matrix, a 3x3 :
[1 2 3
4 5 6
7 8 9]
And I have 9 edit boxes. and I want to load the numbers so editbox1 = 1, editbox2 = 2 and so like that until editbox9 = 9. How Do I do that ?
And there is one more matix into the save a 2x2
[11 22
33 44]
and I would like to save them into editbox10 = 11, editbox11 = 22, editbox12 = 33 and editbox13 = 44
What is the code?
Walter Roberson
2012년 7월 5일
[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 : numel(fieldvals)
set( YourEdithandles(K), 'String', num2str( fieldvals(K) ) );
end
Notice that the only difference between this and what I originally posted was to change "length" to "numel", exactly as described in my comment above.
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
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
2012년 7월 7일
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
Walter Roberson
2012년 7월 8일
Unfortunately my system is claiming it cannot find postimage.org even though I can google it. Anyhow, could you post the image somewhere else?
Walter Roberson
2012년 7월 8일
YourEditHandles = [handles.editbox1, handles.editbox2, handles.editbox3, handles.editbox4, handles.editbox5, handles.editbox6, handles.editbox7, handles.editbox8, handles.editbox9];
And if your actual handle names involve Editbox instead of editbox then use whatever you have, in order, so that the 5th entry in the vector corresponds to your "edit box 5"
Mikkel
2012년 7월 8일
[filename pathname] = uigetfile('*.mat','Select the MATLAB code file');
L = load( fullfile( pathname, filename ) );
fieldvals = L.Soil_profile;
YourEditHandles = [handles.edit1, handles.edit2, handles.edit3,; handles.edit4, handles.edit5, handles.edit6,; handles.edit7, handles.edit8, handles.edit9];
for K = 1 : numel(fieldvals)
set( YourEdithandles(K), 'String', double2str( fieldvals(K) ) );
What wrong here? Thought I did what you said. It just gave me this error.
??? Undefined function or method 'YourEdithandles' for input arguments of type 'double'.
Error in ==> loadproblem>loadbutton_Callback at 402 set( YourEdithandles(K), 'String', double2str( fieldvals(K) ) );
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> loadproblem at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)loadproblem('loadbutton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Mikkel
2012년 7월 8일
편집: Mikkel
2012년 7월 8일
Nice it workes!!!!! but how do I get the Load_dim in also? right now its only the Soil_profile,
Do I type like this?
[filename pathname] = uigetfile('*.mat','Select the MATLAB code file');
L = load( fullfile( pathname, filename ) );
fieldvals1 = L.Soil_profile;
fieldvals2 = L.Load_Dim;
YourEditHandles1 = [handles.edit1, handles.edit2, handles.edit3,; handles.edit4, handles.edit5, handles.edit6,; handles.edit7, handles.edit8, handles.edit9];
YourEditHandles2 = [handles.edit10, handles.edit11,; handles.edit12, handles.edit13];
for K = 1 : numel(fieldvals1)
set( YourEditHandles1(K), 'String', num2str( fieldvals(K) ) );
end
for K = 2 : numel(fieldsvals2)
set( YourEditHandles2(K), 'String', num2str( fieldvals(K) ) );
end
Because it doesnt work
Walter Roberson
2012년 7월 8일
for K = 1 : numel(fieldsvals2)
set( YourEditHandles2(K), 'String', num2str( fieldvals2(K) ) );
end
Mikkel
2012년 7월 8일
Nice THX, now my little example works perfect! but in my original matlab gui Ive run into a little problem, the 7x10 matrix I need to put into my load, is a double.
I get this error:
??? Error using ==> set Invalid handle object.
Error in ==> boetten>load_Callback at 1483 set( YourEditHandles5(K), 'String', ( 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
Walter Roberson
2012년 7월 8일
How do you initialize YourEditHandles5 ?
You only spoke before about having two sets of edit boxes, not five or more sets ?
Mikkel
2012년 7월 8일
I made a little exampel for my self so it would be easyer to explain to you and for me to understand. Everything in the exampel workes perfectly and so does my "real" matlab gui, except for the one matrix, the 7x10 matrix that is a double. That one will not load... All of the other ones workes fine, I got 7 "youredithandles" and all except that one workes perfectly
Walter Roberson
2012년 7월 8일
Put a breakpoint at that line, and run the code. When the line is reached, at the command prompt, give the commands
size(YourEditHandles5)
ishandle(YourEditHandles5)
K
size(fieldvals5)
and let us know what it shows.
Also please show the code that constructs fieldvals5 and YourEditHandles5
Walter Roberson
2012년 7월 9일
I do not presently have access to MATLAB. I am trying to decide which new computer to buy, after which I will need to order a copy of MATLAB.
Mikkel
2012년 7월 9일
Okay, Ive found the problem but dont know how to solve it, its because some of my edit boxes are "NaN" and I dont want to load them. I can't put a zero because then there will be a zero, and Ive found out I can't put NaN in. So what do I put in?
Walter Roberson
2012년 7월 9일
What do you want to put there?
if isnan(fieldvals(K))
set( YourEditHandles(K), 'String', {''} ); %or to suit
else
set( YourEditHandles(K), 'String', num2str(fieldvals(K)) );
end
Mikkel
2012년 7월 9일
편집: Mikkel
2012년 7월 9일
Hmm how can I explain it, if you look at the picture of the matrix I made of the 3x3. If I dont want anything saved into the middle, (editbox5) what do I type? because I cant just remove it, then I wouldnt be a 3x3 matrix.
If we change the matrix to:
[ 1 2 3
4 NaN 6
7 8 9]
How do I load that one?
Walter Roberson
2012년 7월 9일
An edit box has to have something even if that something is the empty string.
The code structure I show just above would detect NaN in the input matrix and make it show as the empty string in the empty box.
Mikkel
2012년 7월 9일
okay, let me see if I can explain this:
My original matrix looks like this.
Soil_profile = [NaN str2num(get(handles.edit1,'string')) NaN NaN NaN NaN NaN NaN NaN NaN;
NaN str2num(get(handles.edit2,'string')) NaN NaN str2num(get(handles.edit7,'string')) NaN NaN NaN NaN NaN;
NaN str2num(get(handles.edit3,'string')) NaN NaN str2num(get(handles.edit8,'string')) NaN NaN NaN NaN NaN;
NaN str2num(get(handles.edit4,'string')) NaN NaN str2num(get(handles.edit9,'string')) str2num(get(handles.edit13,'string')) str2num(get(handles.edit17,'string')) str2num(get(handles.edit21,'string')) str2num(get(handles.edit25,'string')) str2num(get(handles.edit29,'string'));
NaN str2num(get(handles.edit5,'string')) NaN NaN str2num(get(handles.edit10,'string')) str2num(get(handles.edit14,'string')) str2num(get(handles.edit18,'string')) str2num(get(handles.edit22,'string')) str2num(get(handles.edit26,'string')) str2num(get(handles.edit30,'string'));
NaN str2num(get(handles.edit6,'string')) NaN NaN str2num(get(handles.edit11,'string')) str2num(get(handles.edit15,'string')) str2num(get(handles.edit19,'string')) str2num(get(handles.edit23,'string')) str2num(get(handles.edit27,'string')) str2num(get(handles.edit31,'string'));
NaN NaN NaN NaN str2num(get(handles.edit12,'string')) str2num(get(handles.edit16,'string')) str2num(get(handles.edit20,'string')) str2num(get(handles.edit24,'string')) str2num(get(handles.edit28,'string')) str2num(get(handles.edit32,'string'))]
its easyer if you copy into a notebook and see it correctly.
THe reason why Ive put NaN into my matrix is because it use to get its data from a excel file. And now Ive made this gui with your help. The First "edixbox1" had the coordination 1,2. So I had to make a Non number for the coordinate 1,1.
But now I dont know what to do with my load. I cant change my matrix because that will take forever due to the complexity of my program. So I'm asking, what to do?
Because I really only need to load the editboxes in my matrix, but its a 7x10 matrix, and if I remove the NaN, it will not become the same matrix.
Do you understand :)? (If I where you I wouldnt ;P)
Mikkel
2012년 7월 9일
편집: Mikkel
2012년 7월 9일
Remember to read the post before this one first
If i try removing the NaN in my load. Like this
YourEditHandles5 = [handles.edit1;
handles.edit2 handles.edit7;
handles.edit3 handles.edit8;
handles.edit4 handles.edit9 handles.edit13 handles.edit17 handles.edit21 handles.edit25 handles.edit29;
handles.edit5 handles.edit10 handles.edit14 handles.edit18 handles.edit22 handles.edit26 handles.edit30;
handles.edit6 handles.edit11 handles.edit15 handles.edit19 handles.edit23 handles.edit27 handles.edit31;
handles.edit12 handles.edit16 handles.edit20 handles.edit24 handles.edit28 handles.edit32]
So only the edit handles that I want to load, it gives me this error which I can understand why.
??? Error using ==> vertcat CAT arguments dimensions are not consistent.
Error in ==> boetten>load_Callback at 1485 YourEditHandles5 = [handles.edit1;
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
But cant understand how to solve it.
Walter Roberson
2012년 7월 9일
Use a vector, not a matrix. Especially not a matrix that cannot decide whether it is one entry per row or 7 entries per row.
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
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 Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)