フィルターのクリア

how to resolve "Conversion to cell from double is not possible." error

286 ビュー (過去 30 日間)
ram vanguri
ram vanguri 2015 年 7 月 17 日
編集済み: ali hamzah 2024 年 7 月 17 日 11:58
Can someone point out what I am doing wrong.
a=cell(1,2);
for i=1:2
a{i}=mat2cell(zeros(8,8,2),8,8,2);
a{1}(:,:,1)=randi(8,8);
when i run the above lines i am getting error shown below. error:"Conversion to cell from double is not possible."
how to assign or modify the values in the cell. thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 17 日
編集済み: Azzi Abdelmalek 2015 年 7 月 17 日
a=cell(1,2);
for i=1:2
a(i)=mat2cell(zeros(8,8,2),8,8,2);
a{i}(:,:,1)=randi(8,8);
end

その他の回答 (2 件)

Guillaume
Guillaume 2015 年 7 月 17 日
What is the purpose of the call to mat2cell here. mat2cell with the dimension arguments the same size as the matrix just puts the whole matrix into a single cell, so
{zeros(8,8,2} %does exactly the same thing as
mat2cell(zeros(8,8,2),8,8,2) %and is much clearer.
If the intention was indeed to put the matrix into a single cell, then your loop should have been:
for i = 1:2
a{i} = zeros(8,8,2); %or a(i) = {zeros(8,8,2)};
a{i}(:,:,1) = randi(8,8);
end
Or:
for i = 1:2
a{i} = cat(3, randi(8,8), zeros(8,8));
end
Or even simply:
a = mat2cell(cat(3, randi(8,8*2,8), zeros(8*2,8)), ones(1,2)*8, 8, 2)

ali hamzah
ali hamzah 2024 年 7 月 17 日 11:52
編集済み: ali hamzah 2024 年 7 月 17 日 11:58
what the error (Error using Untitled18 (line 12)
Conversion to cell from double is not possible.)
% Ensure all columns except the last one are numeric
for i = 1:(width(data) - 1)
if iscell(data{:, i})
data{:, i} = grp2idx(categorical(data{:, i}));
elseif ischar(data{:, i})
data{:, i} = grp2idx(categorical(data{:, i}));
end
end

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by