Please how i can set the indexes of a vector or matrix in Matlab (exactly like the function set index in python)
Show older comments
I have a csv file which has 2 columns and I want to put the first column as an index so that I can synchronize it with another file. Please Please if anyone has any idea how to do it on matlab
5 Comments
David Hill
on 10 Mar 2020
More description would help along with an example csv file. Do you want the values in column 2 stored at the index in column 1? What about the values of other indexes that are not listed in column 1? Will they be zero or nan?
Inouss
on 10 Mar 2020
Luna
on 10 Mar 2020
Can you share as attachment an example of both csv's and the columns you want to synchronize. You may use tables for that. Tables can easily be synchronized with time column or joined with key variables.
Inouss
on 10 Mar 2020
Accepted Answer
More Answers (1)
David Hill
on 10 Mar 2020
B=zeros(max(A(:,1)),1);
B(A(:,1))=A(:,2);
If you don't like all the zeros, then you could use a sparse matrix.
B=sparse(A(:,1),1,A(:,2));
Categories
Find more on Logical 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!