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
Stephen23 2016년 8월 8일
@Mekala balaji: please show us the desired output as well.
My output should be:
pass OK Out OK OK Out
pass OK Out OK OK Out
fail OK OutSpec OutSpec OK OutSpec
pass OK Out OK Out Out
pass OK Out OK OK Out
fail OK OutSpec OutSpec OutSpec OutSpec
Stephen23
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?
Mekala balaji
Mekala balaji 2016년 8월 9일
편집: Walter Roberson 2016년 8월 9일
Sir,
below is my modified input ( I forgot to show this, which is given below):
pass OK Out OK OK Out
pass OK Out OK OK Out
fail OK Out Out OK Out
pass OK Out OK Out Out
pass OK Out OK OK Out
fail OK Out Out Out Out

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2016년 8월 8일
편집: Stephen23 2016년 8월 8일

0 개 추천

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'

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 6일

0 개 추천

mask = strcmp(YourCell(:,1), 'fail');
YourCell(mask,[3 6]) = {'Outspec'};

댓글 수: 3

Mekala balaji
Mekala balaji 2016년 8월 6일
Sir,
I only want to replace "Out" as "Outspec", not entire row.
Walter Roberson
Walter Roberson 2016년 8월 6일
The entire row is not changed. Only columns 3 and 6 are changed. Did you try the code?
Sir,
The "Out" is not fixed (it vary, not only in column 3&6). The modified input is below, and in "fail" row, just only replace "Out---> OutSpec"
pass OK Out OK OK Out
pass OK Out OK OK Out
fail OK Out Out OK Out
pass OK Out OK Out Out
pass OK Out OK OK Out
fail OK Out Out Out Out

댓글을 달려면 로그인하십시오.

질문:

2016년 8월 6일

편집:

2016년 8월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by