How to read file in matlab GUI

조회 수: 1 (최근 30일)
Muhammad Haziq
Muhammad Haziq 2019년 9월 22일
댓글: Ankit 2019년 9월 23일
Hi,
I want to read a file through matlab gui but unable to read its content completely I use the same code in m.file its working over there but now when I want to do it through GUI but it is not working. I am uploading GUI and a file to read throuh gui. Can anybody help me.

답변 (1개)

Ankit
Ankit 2019년 9월 22일
Please don't forget to pre-allocate the loop variables
According to your GUI and given input conditions, line(i)==6 and line(i) ==3 these condition are not met. You already defined Button_press = 0 but not e_rewarded. just for an e.g. when you define your variable e_rewarded to some value/random array it will not throws any error.
if line(i)==3
Button_press(bp)=line(i+1);
bp=bp+1;
end
if line(i)==6
e_rewarded(erw)=line(i+1);
bp=bp+1;
end
But when you run the same code I think you mean what you have written in pushbutton1_Callback, still MATLAB throws the following error:
Undefined function or variable 'e_rewarded'
Are you sure that your m.file works fine even without defining variable e_rewarded?
Could you please attached it too ?
  댓글 수: 2
Muhammad Haziq
Muhammad Haziq 2019년 9월 23일
Hi,
My basic cocern is not e_rewarded. I am attaching my file.and ıt works like this it will go through all line and when ever line euals to 3 it stores the next line value to that specific variable, when line equals to 4 it stores the next line value to some other specific variable.
when I try the same code with gui it didn't work.
Ankit
Ankit 2019년 9월 23일
Hello Muhammad,
I already mentioned that you need to defined the loop variables.
Code in *.m script and GUI are not completely same.
Following condition (line(i) ==3) is not met
line.PNG
if line(i)==3
Button_press(bp)=line(i+1);
bp=bp+1;
end
You will not get any error as you defined the variable with the value of 0.
For your understanding just rename the Button_press with Button_press1 you will get an error.
In your GUI you didnt defined /pre-allocate your loop variables. Please define/pre-allocate with some values you will not get any error. I tried and tested the GUI it works fine after defined.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by