Strange Cell Array error

8 ビュー (過去 30 日間)
Jason
Jason 2018 年 6 月 21 日
コメント済み: Jason 2018 年 6 月 21 日
Hello. I have a cell array in a uitable that I want to find the min of the columns 2,3,4,5 - and for each column, extract the z position from the file name that corresponds to that minimum.
for h=1:4 %first column is filename, so start at 2
h
data(:,h+1)
class(data)
c2=str2num(cell2mat(data(:,h+1))) %Select column fwhmH=2 etc.
c2min=min(c2(:));
c2idx=find(c2==c2min);
text=cell2mat(file(c2idx));
C = strsplit(text,'zPos_');
class(C);
C=cell2mat(C(2));
D=strsplit(C,'.tif')
data2=horzcat(data2,D(1))
end
set(handles.uitable2,'data',data2)
However, on the 3rd loop (h=3), for the following code
h
data(:,h+1)
class(data)
c2=str2num(cell2mat(data(:,h+1))) %Select column fwhmH=2 etc.
I get the following output and error
h =
3.00
ans =
3×1 cell array
{'8317' }
{'10974'}
{'14623'}
ans =
'cell'
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
I can't understand why as on the 1st & 2nd loop that correctly works, the data is of the same type - i.e. cell array
  2 件のコメント
Dennis
Dennis 2018 年 6 月 21 日
編集済み: Dennis 2018 年 6 月 21 日
Your cell entries are strings. You get that error message because '8317' has 4 chars and your other 2 cell entries have 5.
c2 = cellfun(@str2double,data(:,h+1));
Jason
Jason 2018 年 6 月 21 日
Thankyou

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

採用された回答

Stephen23
Stephen23 2018 年 6 月 21 日
編集済み: Stephen23 2018 年 6 月 21 日
c2 = str2double(data(:,h+1))
  1 件のコメント
Jason
Jason 2018 年 6 月 21 日
Thanks

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

その他の回答 (1 件)

Sayyed Ahmad
Sayyed Ahmad 2018 年 6 月 21 日
try this codes
data={'8317';'10974';'14623'}
for i=1:3
c2(i)=str2num(data{i})
end

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by