MATLAB Answers

Inouss
0

Please how can I store all my matrix?

Asked by Inouss
on 13 Jun 2019
Latest activity Commented on by Inouss
on 13 Jun 2019
Hello,
I made a for loop that imports a database (several matrix), I wanted to store all matrices on a single matrix but I can store only the last one. Please how can I store all the matrix?
for i = 1:length(find([d.isdir]==0))-1
channel = "/channel_"+i+".dat";
location = strcat(location_filename,channel);
location= sprintf('% s', location);
%import Matrix
channel = [importdata(location)];
end
y = channel

  0 Comments

Sign in to comment.

1 Answer

Answer by James Tursa
on 13 Jun 2019
 Accepted Answer

Maybe use a cell array:
channel{i} = [importdata(location)];
Then at the end you can work with the individual matrices as channel{i}, or concatenate all of the channel elements into a single larger matrix.

  3 Comments

Thank you James but it does not work. here is the error message
Curly brace assignment into a string expects a character vector.
Error in importfile (line 18)
channel{i}= [importdata(location)];
Sorry, I forgot you had previously used that variable name. Simply pick another name. E.g.,
channels{i} = [importdata(location)];
You might want to pre-allocate channels prior to the loop.
Thank you James it works but I would like to access these matrices and be able to draw a plot with all the data.
ps: the matrices contain 2 columns and thousands of lines

Sign in to comment.