ERROR SELECTING MULTIPLE FILES
1 回表示 (過去 30 日間)
古いコメントを表示
HI!
i have attached as much information as possible
so i have written a code to open a text file selected by user and to do whatever based on what the user chooses. this is the code that works.
[file, path] = uigetfile('.txt');
if isequal (file, 0)
disp ('user selected cancel')
else
disp(['user selected', fullfile(path,file)]);
end
COP = importdata(fullfile(path,file));
code works, no worries.
NOW the issue i am having is when the user wants to select and import multiple files. i have tried to do it using a for loop but it opens a structure and i dont know how to handle a struct. the loop i followed is similar to the one found in this link.. https://au.mathworks.com/matlabcentral/answers/71197-error-in-uigetfile-multiselect . so before anyone comes at me for not "trying" i have also tried stringcat and a lot of other methods, none of which worked.
its spits out this error
Error using importdata (line 139)
Unable to open file.
Error in 'trying' (line 13)
COP = importdata(fullfile(path,file));
COULD someone please provide some insight into why this is happening???? or what is wrong with my loop?
if you have nothing helpful to say please just don't say it. thanks.
sincerely a desperate student.
0 件のコメント
採用された回答
Simon Allosserie
2021 年 2 月 26 日
編集済み: Simon Allosserie
2021 年 2 月 26 日
The moment you select multiple files, file becomes a cell array.
Just run this in your command window and select a few files to see the data formats. Don't put ";" so you see how it looks.
[file, path] = uigetfile("Select something", 'MultiSelect', 'on')
You cannot make a fullfile of file, because it is no longer a string, but a cell array. Of course, Matlab cannot concatenate path (a string) with file (a cell array).
This means you will have to loop through your array and use something like
fullfile(path, file{1})
By the way, the answer you so nicely link in your question, contains the above information if you would read Jan's answer carefully.
2 件のコメント
Simon Allosserie
2021 年 3 月 1 日
編集済み: Simon Allosserie
2021 年 3 月 1 日
Hi Diala
If you wouldn't have so purposefully stated that in your question, I wouldn't have come back to it.
You should know that no one is born a matlabbing genius. We are all just trying to get better, just like you. We do this by interacting with this community and getting helped by many experts that provide us with answers we would ourselves never have thought of. There is no need to put yourself below others. I am posting questions myself regularly here, because sometimes I don't find the clue either.
There's just no need to shield yourself in your questions even before people are giving you answers. Every answer you get, requires someone's time and effort. Yes, I have also already received sassy responses. But they are still responses that most of the time will get you on the way, and help you form your thinking pattern.
So don't be hard on yourself. Also, don't be hard on others. If you don't find answers to your problems after researching yourself, always ask here. In the end, there will always be someone to help you. Over time, you will be one of the persons answering questions here. Think about that for a second. How nice will that be :)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!