Having each row compare its string with other rows within the problem and getting corresponding data relative to the string in other columns.
Show older comments
Hello,
I am stuck at this point where I want to run a for loop through the column with multiple rows has strings. I want to compare each row to its adjacent row if same then take its corresponding values. Each time the string is different.
I am unable to use strcmp/pattern as I can't list all the strings that need to be compared.
I was hoping if I could run a for loop on the first column and each row is compared to every ROW and same string will extract itself together.
Have attahced a sample file with Dummy variables.
*******************************************************************************************************************************************************************
A = readtable("C:\Users\gudlu\OneDrive\Documents\Matlab\Book1.xlsx");
headers = table2array(A(:,1));
Sorry unable to move beyond this.
5 Comments
Stephen23
on 19 Aug 2023
Please show the expected output using your uploaded data file.
the cyclist
on 19 Aug 2023
I don't understand what you want to do. The phrase "compare each row to its adjacent row if same then take its corresponding values" is unclear to me.
Here is a suggestion for making your question clearer:
- Post a much smaller version of the input file, with just enough rows to illustrate what you are trying to do.
- Post the output you expect from that smaller input file. Don't just describe the output you want. Show the output you want.
Sai Gudlur
on 20 Aug 2023
The sample data file you uploaded includes the text ABCDF four times, on rows 1, 41, 45, and 49. You only include rows 1, 45, and 49 in the desired output, i.e. row 41 is excluded. I do not understand the rule, perhaps I missed that part of your explanation: please clarify why row 41 is not part of the output.

I also don't understand how your exected output matches your description "I want to compare each row to its adjacent row if same then take its corresponding values". As far as I can tell, you did not compare adjacent rows, but rather all rows with the text in cell A1 (plus some as-yet secret rule for ignoring other rows). In any case, rows 45 and 49 are not adjacent to A1, so it is unclear to me what you want.
Sai Gudlur
on 20 Aug 2023
Accepted Answer
More Answers (0)
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
