Load data (.csv or .isf) from any directory to process in Matlab Standalone Application (App Designer)

11 views (last 30 days)
I have .csv file to be processed and plot the figure(x,y). I run the app in standalone application and insert the data file. It can process data that is located on Desktop only (that means it can process data which are in same directory with App shortcut).
I want that my app should be able to process .csv data from any directory (any directory from my pc or from removeable disk /usb). I need help. Can anyone please suggest me how to do that ?
Currently I am using following code to load .csv data and plot (x,y).
[filename, path]=uigetfile('*.csv'); %load .csv file
app.DataEditField.Value=filename; %to show the file name is text edit field
B= app.DataEditField.Value %load data in a B
D1= readmatrix(B) %read matrix
x = D1(:,1); %find x
y = D1(:,2); %find y
plot(app.UIAxes,x,y); % Plot (x,y) in UI axes

Answers (1)

dpb
dpb on 12 Aug 2022
Well, you got the filename and path to it, but you didn't use the path --
...
D1= readmatrix(fullfile(path,filename));
...
You don't have any error handling in the above -- if the user cancels out of uigetfile, the return values for path and filename will be numeric "0" values which are not valid for path for filename and so your app will crash and burn.
See the examples at @doc:uigetfile to see samples of handling the error condition.
I'd suggest you should also probably display the path as well as the file name in your GUI somewhere -- either in the existing text box or add another for the file location if the fully-qualified filename turns out to be too long.
  2 Comments
MD UDDIN
MD UDDIN on 12 Aug 2022
Showing an error, It does not work.
I want to insert .csv/.isf file from any directory then my standalone app should work process tha data. Currently my app is working for only signle directory (Desktop).
dpb
dpb on 12 Aug 2022
Edited: dpb on 12 Aug 2022
It doesn't do any good to paste the error without any context of the precise code that called it. Somehow you've written a line of code that thinks D1 is a function, not a variable.
We've no idea what line 789 is; we can't see your terminal from here...
But, the fundamental problem is probably before that; show the code that's attempting to open and read the file in context with the error.
Did you incorporate error handling in the routine as I suggested -- you sure that isn't the cause of the problem that a file wasn't selected and the code tried to continue instead? We simply have no way to know without suffiicient context to see...

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!