Please how i can set the indexes of a vector or matrix in Matlab (exactly like the function set index in python)

4 ビュー (過去 30 日間)
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 件のコメント
Luna
Luna 2020 年 3 月 10 日
編集済み: Luna 2020 年 3 月 10 日
Is first column miliseconds? It goes like that:
1303132929
1303132930
1303132931
1303132932
Also how do you want to synchronize or resample these 2 tables? How do you want to fill your missing values? Do you have sampling rate?

サインインしてコメントする。

採用された回答

Luna
Luna 2020 年 3 月 10 日
Hello,
I wrote some codes for you and I am going to share some links so that you can read in documentation and it will help.
Please read my comments below:
chan1_table = readtable('chan1.csv'); % read table 1. Your files must be in your work folder, otherwise use full path name.(Ex: 'C:/Users/.../chan1.csv')
chan2_table = readtable('chan2.csv'); % read table 2
% your both table have Var1 and Var2 variables. Var1 variables are your
% time column.
chan1_table.Var1 = milliseconds(chan1_table.Var1); % convert Var1 into milliseconds. You can use seconds, minutes or any other duration functions.
chan2_table.Var1 = milliseconds(chan2_table.Var1); % same as chan1_table.
%% convert both tables to time table according to their time column.
TT1 = table2timetable(chan1_table,'RowTimes','Var1');
TT2 = table2timetable(chan2_table,'RowTimes','Var1');
%% choose a time step
dt = milliseconds(1); % I choose 1 milliseconds because I don't know what it is. You can change as you wish.
% For example: dt = seconds(10)
% synchronize your table like below:
synched_table = synchronize(TT1,TT2,'regular','nearest','TimeStep',dt); % you can also use 'SampleRate',Fs. Fs must be in Hz(frequency)

その他の回答 (1 件)

David Hill
David Hill 2020 年 3 月 10 日
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));
  1 件のコメント
Inouss
Inouss 2020 年 3 月 10 日
Thank you David, see above the examples of my csv files

サインインしてコメントする。

カテゴリ

Find more on Matrices and Arrays 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!

Translated by