How to store value in a two dimentinal array in matlab
1 view (last 30 days)
Show older comments
I generate an array by this way.
p=dir('C:\Users\Shahriar\Documents\EEGProject\*.csv');
num=cell(size(p));
n=length(p);
for i=1:n
[num{i}]=csvread(p(i).name,1,1);
end
I try to store value in a two dimensional array B using following code, but cannot store all of them.
for i=11:20
e = unique(num{i,1}(:,2));
B = cell(size(e));
for k = 1:numel(e)
[B{k}] = num{i,1}(num{i,1}(:,2)==e(k),:);
end
end
Now How can i store all value of num{i,1} to B. please suggest.
1 Comment
dpb
on 21 Jun 2018
Describe what you actually want B to contain in the end; why are you convoluting the code by stuffing an array into a cell array only to dereference it again in much more complex fashion than just using each array directly when read by csvread?
Answers (1)
dpb
on 20 Jun 2018
Every time you execute
B = cell(size(e));
you create a new empty cell array of size(e) empty matrices so for every loop over i starts with a new array and the end result is just the last one, all the previous having been created but then destroyed.
The cell function needs to be outside the loop instead, then you don't need the inner loop at all--
B = cell(10);
for i=11:20
B(i-i1+1) = unique(num{i,1}(:,2));
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!