How to store value in a two dimentinal array in matlab
显示 更早的评论
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 个评论
dpb
2018-6-21
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?
回答(1 个)
dpb
2018-6-20
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
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!