How to store columns of different lengths using cells

3 ビュー (過去 30 日間)
Fede C 2018 London
Fede C 2018 London 2019 年 3 月 11 日
編集済み: per isakson 2019 年 3 月 12 日
Dear all,
I understand that in order to store column vectors of different length one ought to use cells. I fail to see my mistake in attempting to do this in the code below. I get the following error message: 'Array indices must be positive integers or logical values' but I don't really know what that means. Here's my attempt:
clc;
clear;
[~,~,raw] = xlsread( '21series',8) ;
dates = cellfun( @(x) sscanf( x, 'Q%d %d' ), raw(2:end,1), 'UniformOutput', false ) ;
dates = horzcat( dates{:} ).' ;
headers = raw(1,2:end) ;
select = raw(2:end,2:end) ; % Cell array mixed str/values.
select(cellfun( @ischar, select )) = {NaN} ; % Cell array NaN/values
select = cell2mat( select ) ; % Numeric array.
[nnn,kkk] = size(select);
for colidtrim=1:kkk;
datalogical(:,colidtrim)=~ isnan(select(:,colidtrim));
end
newData=cell(1,kkk);
for colidback2num=1:kkk
trimtempstoreCol = select(~isnan(select(:,colidback2num)),colidback2num);
newData{trimtempstoreCol};
end
Any suggestions?
Many thanks
  1 件のコメント
Bob Thompson
Bob Thompson 2019 年 3 月 12 日
Which line specifically gives the error?
Is 'trimtempstoreCol' always a postive integer?

サインインしてコメントする。

採用された回答

per isakson
per isakson 2019 年 3 月 12 日
編集済み: per isakson 2019 年 3 月 12 日
I assume that you intend to put successive values of trimtempstoreCol into cells of newData.
To do that, replace
newData{trimtempstoreCol};
by
newData( 1, colidback2num ) = {trimtempstoreCol};
or by
newData{ 1, colidback2num } = trimtempstoreCol;
That will make your code run.
PS: datalogical is never used.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by