I have the following output
Mek Mek
Lahi Ar
Puni N2
Ar Mek
N2 Mek
Mek Lahi
Lahi Puni
Puni BM2
I have uncommon list:
Ar
N2
BM2
I want to remove the entire row if any of the uncommon list appears in that row. I also want to delete if the first column data and second column data equal in the particulR ROW, and remove the entire row. For example, in first row (first &second column), the data is same (Mek). So, I want to delete the entire row. And, in second row, second column, the data is Ar, because it is in uncommon list, so delete entire row. In fifth row, in first column data is N2, which is included in the uncommon list, so remove entire row. Please kindly help, how to do this. The size of out put data and uncommon list may vary. Many thanks in advance.

댓글 수: 2

the cyclist
the cyclist 2015년 10월 1일
Are these values stored in cell arrays?
Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 10월 24일
Yes sir

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

 채택된 답변

the cyclist
the cyclist 2015년 10월 1일

0 개 추천

data = {
'Mek', 'Mek';
'Lahi', 'Ar';
'Puni', 'N2';
'Ar', 'Mek';
'N2', 'Mek';
'Mek', 'Lahi';
'Lahi', 'Puni';
'Puni', 'BM2'};
uncommon = {'Ar','N2','BM2'};
% Remove rows with uncommon
isUncommonElement = ismember(data,uncommon);
rowHasUncommon = any(isUncommonElement,2);
data(rowHasUncommon,:) = [];
% Remove all same
isEqualToFirstElementInRow = strcmp(data,repmat(data(:,1),[1 size(data,2)]));
rowHasAllEqual = all(isEqualToFirstElementInRow,2);
data(rowHasAllEqual,:) = []

댓글 수: 5

Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 10월 2일
Thank you sir, It works. I have one question, in one of output it contain hyphens. like 'Mek' I want to remove them, kindly help me how to remove them.
Sincerely, JAK
If you want to remove an entry that is just a hyphen (with nothing else), then you can add '-' to your uncommon list.
If you want to strip hyphens out of all strings in a cell array like
A = {'A-rod','B-ball','C-SPAN'}
then
A = regexprep(A,'-','')
Sir,
my input data is:
finalscore:
-1 10 NaN NaN NaN NaN
NaN NaN 20 NaN -1 NaN
-1 -1 NaN NaN NaN NaN
NaN NaN NaN NaN NaN -1
NaN NaN NaN NaN NaN -1
NaN NaN NaN -1 NaN NaN
recipeHTD:
[] 'A' 'B' 'C' 'D' 'E' 'F'
'A' [] [] [] [] [] []
'B' [] [] [] [] [] []
'C' [] [] [] [] [] []
'D' [] [] [] [] [] []
'E' [] [] [] [] [] []
'F' [] [] [] [] [] []
for all entries whos finalscore>=0, then store finalscore, toolID,and recipeHTD. My code is as below:
toolID='RAV2'';
count=0;
for i=1:size(finalScore,2)
for j=1:size(finalScore,1)
if(finalScore(j,i)>=0)
count=count+1;
scoreTable{count,1}=toolID;
scoreTable{count,2}=finalScore(j,i);
scoreTable{count,3}=char(char(recipeHTD(j+1,1)));
scoreTable{count,4}=char(char(recipeHTD(1,i+1)));
else
disp('no data');
end
end
end
But unfortunatly my output contains hyphens before and after which I dont want. I am getting the below output:
scoreTable:
'RAV2' 10 'A' 'B'
'RAV2' 20 'B' 'C'
Please kindly help me, how to avoid these hyphens from the output. Many thanks in advance.
You are not talking about hyphens. Those are single quotes.
This is not very easy. Those quotes are not part of the input. They are just how MATLAB displays strings. I found a post on StackOverflow that explains how to do it. I have pasted an example below.
%// Input
inputArray = {
'a' 'b' 'Fa' 'Fb' 'Xn' 'Fx' 'sign Fa*Fx'
'0.70000' '0.90000' '-0.19592' '0.33887' '0.77327' '0.02896' '-'
'0.70000' '0.77327' '-0.19592' '0.02896' '0.76383' '0.00206' '-'
'0.70000' '0.76383' '-0.19592' '0.00206' '0.76316' '0.00012' '-'
'0.70000' '0.76316' '-0.19592' '0.00012' '0.76312' '0.00000' '-' };
paddedInputArray = strcat(inputArray,{' '}); %// add whitespace
%// Convert to char array
inputCharacterArray = char(paddedInputArray{:})
% Get size parameters
[m,n] = size(paddedInputArray);
p = size(inputCharacterArray,2);
% Create a char array "replica" of input cell array
outputCharacterArray = reshape(permute(reshape(inputCharacterArray.',p,m,[]),[1 3 2]),n*p,m).';
% Display the char array
disp(outputCharacterArray)
Sir,
One kind help, I also want to remove all the names starting with the leters 'Ma' in below code as given by you:
data = {
'Mek', 'Mek';
'Lahi', 'Ar';
'Puni', 'N2';
'Ar', 'Mek';
'N2', 'Mek';
'Mek', 'Lahi';
'Lahi', 'Puni';
'Puni', 'BM2'};
uncommon = {'Ar','N2','BM2'};
% Remove rows with uncommon
isUncommonElement = ismember(data,uncommon);
rowHasUncommon = any(isUncommonElement,2);
data(rowHasUncommon,:) = [];
% Remove all same
isEqualToFirstElementInRow = strcmp(data,repmat(data(:,1),[1 size(data,2)]));
rowHasAllEqual = all(isEqualToFirstElementInRow,2);
data(rowHasAllEqual,:) = []
Many thanks in advance sir.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2015년 10월 1일

댓글:

2015년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by