ERROR SELECTING MULTIPLE FILES

1 visualización (últimos 30 días)
diala yazbeck
diala yazbeck el 26 de Feb. de 2021
Editada: Simon Allosserie el 1 de Mzo. de 2021
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.

Respuesta aceptada

Simon Allosserie
Simon Allosserie el 26 de Feb. de 2021
Editada: Simon Allosserie el 26 de Feb. de 2021
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 comentarios
diala yazbeck
diala yazbeck el 1 de Mzo. de 2021
Thanks for your help. It worked now...
i do however have a few things to say to you. Your answer could have gone without 'By the way, the answer you so nicely link in your question, contains the above information if you would read Jan's answer carefully', its uncalled for and rude. I'm so sorry for asking for help and inconviencing you.
Seeing as this question was such an inconvenience to you, i feel like you should know that the reason the information in Jans question (WHICH I DID READ and try to apply) did not work was because of Matlab errors. So kindly, keep your sarcasm to yourself and be kind. Its people like you that make me not want to ask questions and make me not want to continue my proffesion. I have to work 500 times harder to prove myself to people like you. I'm so sorry for attempting matlab and will be sure to handle everything else by myself and not ask for help because of yours and others sarcastic comments. Not everyone is born a matlabbing genius like yourself.
Simon Allosserie
Simon Allosserie el 1 de Mzo. de 2021
Editada: Simon Allosserie el 1 de Mzo. de 2021
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 :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by