How to replace the matching cell
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have the below cell matrix,
pass OK Out OK OK Out
pass OK Out OK OK Out
fail OK Out OK OK Out
pass OK Out OK OK Out
pass OK Out OK OK Out
fail OK Out OK OK Out
If in first column of particular row is "fail" then replace the Out as "Outspec". Kindly someone help how to do this.
4 个评论
Stephen23
2016-8-8
编辑:Stephen23
2016-8-8
Your input and output arrays do not match, according to your description: your output has "Out" in position (4,5), but the input does not. Where does this "Out" come from ?
Also in columns four and five you have three "OutSpec", but your input array does not show any "Out"s in those columns, as they both contain only "OK"s, and you did not mention that you want to do anything with "OK". Where did these "OutSpecs"s come from?
采纳的回答
Stephen23
2016-8-8
编辑:Stephen23
2016-8-8
This might do what you want:
inp = {...
'pass','OK','Out','OK','OK','Out';...
'pass','OK','Out','OK','OK','Out';...
'fail','OK','Out','Out','OK','Out';...
'pass','OK','Out','OK','OK','Out';...
'pass','OK','Out','OK','OK','Out';...
'fail','OK','Out','Out','Out','Out';...
}; % from your comment above
out = inp;
idx = strcmp(out(:,1),'fail');
out(idx,2:end) = strrep(out(idx,2:end),'Out','OutSpec')
output:
out =
'pass' 'OK' 'Out' 'OK' 'OK' 'Out'
'pass' 'OK' 'Out' 'OK' 'OK' 'Out'
'fail' 'OK' 'OutSpec' 'OutSpec' 'OK' 'OutSpec'
'pass' 'OK' 'Out' 'OK' 'OK' 'Out'
'pass' 'OK' 'Out' 'OK' 'OK' 'Out'
'fail' 'OK' 'OutSpec' 'OutSpec' 'OutSpec' 'OutSpec'
0 个评论
更多回答(1 个)
Walter Roberson
2016-8-6
mask = strcmp(YourCell(:,1), 'fail');
YourCell(mask,[3 6]) = {'Outspec'};
3 个评论
Walter Roberson
2016-8-6
The entire row is not changed. Only columns 3 and 6 are changed. Did you try the code?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification Ensembles 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!