Delete a cell in an array chosen by a criterion?
이전 댓글 표시
Dear all, I have a cell-array of 9*365. In each cell is a vector of 3*365. First I want to delete every 6th and 7th cell in each row. Then I want to delete them by a criterion in the vector. The third column in every vector stands for the trading volume of a stock. If all rows of this column are zero, then the cell should be deleted. How can I delete the cells? Thank you very much!
댓글 수: 7
Matt J
2013년 1월 21일
If it's 3x365 it's a matrix, not a vector. Or did you mean to type 1x365?
Jan
2013년 1월 21일
If all rows of this column are zero, then the cell should be deleted.
This is unclear, because you are talking about cells of a {9 x 365} cell array. Do you want to delete a row or column of this cell array?
Matt J
2013년 1월 21일
If all rows of this column are zero, then the cell should be deleted.
When a cell is deleted, what should be left behind in its place? Something has to be there so that the cell array continues to be rectangular in shape.
Azzi Abdelmalek
2013년 1월 21일
you are talking about the third column of every vector. Are you sure your vectors are 3x365 and not 365x3?
Thor
2013년 1월 22일
Azzi Abdelmalek
2013년 1월 22일
Your matrices are 3x365 or 365x3?
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2013년 1월 22일
years = 2002:2010; % 9 years
ndy = 337 + eomday(years,2); % days in years
data = cell(1,numel(years)); % create your cell-array
for jj = 1:numel(data)
data{jj} = cell(ndy(jj),1);
c = randperm(ndy(jj));
b = c(1:randi(20));
for ii = 1:ndy(jj)
k = randi([270,288]);
data{jj}{ii} = randi([40,1000],k,2);
if any(ismember(b,ii))
data{jj}{ii}(:,3) = 0;
else
data{jj}{ii}(:,3) = randi([40,1000],k,1);
end
end
end
% solution
for jj = 1:numel(years)
data{jj} = data{jj}...
(~ismember(weekday(datenum(years(jj),1,(1:ndy(jj))')),[1,7]));
for ii = 1:numel(data{jj})
if all(~data{jj}{ii}(:,3))
data{jj}{ii} = [];
end
end
end
카테고리
도움말 센터 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!