MATLAB Answers

New to matlab. Trying to make a script to reorganize excel data

1 view (last 30 days)
Elise Isobel Alexander
Elise Isobel Alexander on 6 May 2021
Answered: David Hill on 6 May 2021
Hello. I have an excel file that contains two columns, column one contains numbers and column two contains strings. I am trying to write some code that allows me to collect the number in the row that I given string is present. For example, for the string 'dog' I want to the program to look for every iteration of 'dog' and grab the number that is in the same row and place it in a column of a new excel file under the column header dog.
Any help is appreciated!
  1 Comment
Rik
Rik on 6 May 2021
Break it into steps you can google or solve yourself.
You will very likely need xlsread, xlswrite and ismember. I don't immediately see why you would need any other function.
Have a read here and here. It will greatly improve your chances of getting an answer.

Sign in to comment.

Answers (1)

David Hill
David Hill on 6 May 2021
a=readcell('yourcellname');
b=unique(a(:,2));
newCell=b';
for k=1:length(b)
newCell(2,k)={a(ismember(a(:,2),b{k}),1)};
end

Tags

Products

Community Treasure Hunt

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

Start Hunting!

Translated by