How to convert the contents of a cell array into specific numbers?
2 次查看(过去 30 天)
显示 更早的评论
Hi guys, I wrote this code to convert the columns 1 and 2 of my cell array into specific numbers as mentioned in the code but no value changed in column 1 and no error is shown even!.
Maybe there is a problem of indexing anyone can help me out plz?
[row_patho, col_patho]=size(Pro_patho_data);
for i=1:1:row_patho
if Pro_patho_data{i,1}>=70
Pro_patho_data{i,1}=11;
end
end
for k=1:1:row_patho
if strcmpi(Pro_patho_data{k,2},'t3b')
Pro_patho_data{k,2}=3;
end
end
Inputs:
73 t2b
59 t1c
58 t3b
78 t3b
wanted_outputs:
11 t2b
59 t1c
58 3
11 3
2 个评论
回答(2 个)
Guillaume
2018-4-4
Pro_patho_data = {73, 't2b'; 59, 't1c'; 58, 't3b'; 78, 't3b'}; %demo data
col1 = cell2mat(Pro_patho_data(:, 1));
col1(col1 > 70) = 11;
Pro_patho_data(:, 1) = num2cell(col1);
Pro_patho_data(strcmpi(Pro_patho_data(:, 2), 't3b'), 2) = {3}
10 个评论
Walter Roberson
2018-4-4
%q means to import quote-delimited strings. You would need '%f%s%f%s%f%f%f'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!