Need all row data after strcmp

try
in = 'AAA';
p = strcmp(in,raw);
if p >= 0
xlswrite('SummaryResult.xlsx',raw1(p),'AAA','A2')
else
0;
end
end
Once I will compare
I want all the row data where AAA is presnt in those column.
Please let me know for brief.

5 Comments

Hi Santosh,
Can you provide an example of a table and the result you expect.
Also if it helps you can take look at the code below. In this line I am filtering all the rows of a table having value in Col1 = 'AAA'.
filteredTable = tab(tab.Col1 == "AAA",:)
Santosh Biradar
Santosh Biradar on 22 Jul 2022
Edited: Santosh Biradar on 22 Jul 2022
Thank you for your responce.
In the SummaryResult Excel, (Attached) . It is having 2 sheets. MissingData and NewlyaddedData.
if 1st Sheet or/And 2nd Sheet, A3 having value aaa and A6 also having aaa (like the same values present in A Column only) then Entire ROW from those sheets will be written separately to new *AAA* Sheet in the Same SummaryResult.xlsx
if 1st Sheet or/And 2nd Sheet, A4 having value bbb and A5 also bbb (the same values present in A Column only)then entire ROW from those sheets will be written separately to new *BBB* sheet in the Same SummaryResult.xlsx
I have attached upated Required SummaryResult.xlxs
Please have a look for ref. Sheet AAA and BBB
Thank you
Jan
Jan on 22 Jul 2022
Edited: Jan on 23 Jul 2022
An Excel file is less useful, because you can import it in different ways. Please post some code, which produces the inout data or a MAT file.
What is the purpose of the line "if p >= 0"? p is a logical array. Do you mean:
if any(p(:))
What is raw1 and raw?
This line is useless - omit it:
0;
Hello @Jan
Here is 1st approach code 1: %%Here I want to find out 'aaa' from sheet->'MissingData', & later list out all Row data present on aaa column new sheet in same excel. This is done with writetable and readtable.
idx = ismember(tOld, tNew, 'rows'); %excels compared
writetable(tOld(~idx,:), 'SummaryResult.xlsx', 'Sheet', 'MissingData','Range','A2') %new sheet prepared with missing data
%%for finding 'aaa' i prepared dummy excel and compared with MissingData sheet
name = {'aaa'};
T = table(name);
writetable(T,'DummyTable.xlsx','sheet','temp');
B = readtable('DummyTable.xlsx','sheet','temp');
B = B(1:end,1:1);
A1 = readtable('SummaryResult.xlsx','sheet','MissingData'); %excels compared
A = A1(1:end,1:1);
idx = ismember(A, B, 'rows');
writeable(A(~idx,:),'SummaryResult.xlsx', 'Sheet', '724_MapDiff','Range','A2')
Second approach Code: Here the purpose is same but i used strcmp.
idx = ismember(tOld, tNew, 'rows'); %excels compared
writetable(tOld(~idx,:), 'SummaryResult.xlsx', 'Sheet', 'MissingData','Range','A2') %new sheet prepared with missing data
[num,txt,raw] = xlsread('SummaryResult.xlsx','NewlyAddedData');
in = 'aaa';
p = strcmp(in,raw(:,1)); % as 'aaa' is present in A column so.
if (p(:))
xlswrite('SummaryResult.xlsx',raw(p),'aaa','A2')
else
%do nothing
end
Please let me know for brief. I also have attached expected SummaryResult.xlsx. Pls look sheet3 and Sheet4.
Thank you
I asked you, what the purpose of "if p >= 0" is. You did not answer this, but post the new line: "if (p(:))". Agaion the purpose is unclear. Do you mean:
if any(p(:))
Do you see, that your can format code in the forum? Please use the corresponding tools.

Sign in to comment.

Answers (0)

Products

Release

R2019b

Asked:

on 22 Jul 2022

Commented:

Jan
on 23 Jul 2022

Community Treasure Hunt

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

Start Hunting!