Combining Pushbutton and Program to Read CSV

1 回表示 (過去 30 日間)
Dimas Agil Roeseno Kambuna
Dimas Agil Roeseno Kambuna 2013 年 3 月 7 日
Hi, I'm a beginner in Matlab
I have made a program in Matlab on the Command Window to import a .csv file. The coding is (step 1):
y=csvimport('apnea.csv); %apnea is the name of file that I want to open
Well, it has worked and produced a variable (step 2) in the Workspace (with name: y, and value <1002x2cell> )
My question is how to connect the program in the Command Window to the Editor GUI:
% --- Executes on button press in Button_Open.
function Button_Open_Callback(hObject, eventdata, handles)
% hObject handle to Button_Open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
...???
so that when the push button is pressed, it will make the process of generating step 1 (import csv) and produced a variabel in step 2?? Have not found the way
Thanks

採用された回答

TAB
TAB 2013 年 3 月 7 日
編集済み: TAB 2013 年 3 月 7 日
When you create any variable in function, its scope is limited to the function workspace. In matlab, each function has its own workspace.
In your case, you have imported csv in function Button_Open_Callback. So variable will be created in its workspace. So you can see this in base workspace.
You can export the variable from function to base workspace using
y=evalin('base','y');
  1 件のコメント
Dimas Agil Roeseno Kambuna
Dimas Agil Roeseno Kambuna 2013 年 3 月 11 日
thanks for your answer... But, finally I prefer to use csvimport and save the result in .mat files... this answer made me understand where is my problem.. Thanks :)

サインインしてコメントする。

その他の回答 (2 件)

Jing
Jing 2013 年 3 月 7 日
Hi Dimas,
Actually you can import csv in the callback. But if you have good reason to do that in base workspace (what you mean by command window), you can also access to the base by EVALIN.
evalin('base','y=0:10');
y=evalin('base','y');
Hope this is what you need!
  1 件のコメント
Dimas Agil Roeseno Kambuna
Dimas Agil Roeseno Kambuna 2013 年 3 月 11 日
thanks for your answer... But, finally I prefer to use csvimport and save the result in .mat files... Thank you guys, I learn something new.. :)

サインインしてコメントする。


Walter Roberson
Walter Roberson 2013 年 3 月 7 日
  1 件のコメント
Dimas Agil Roeseno Kambuna
Dimas Agil Roeseno Kambuna 2013 年 3 月 11 日
thanks for the link.. I learn something more there.. :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHelp and Support についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by