Hello,
I have data in 1008 csv files, each files has 3 column in it. I want to form a matrix using only the first column of each csv file as column vector of matrix, so that I have a matrix with 1008 columns and than do its 2D fft.
How can I form the matrix from csv files?

 채택된 답변

Nadia Shaik
Nadia Shaik 2022년 11월 21일

0 개 추천

Hi Manoj,
I understand that you have data in 1008 csv files and want to extract the first column of each csv file to a matrix.
You can use 'dir' function to read the name of all files with csv extensions and then iterate over the files using a 'for' loop.
To read data from csv files you can use 'readtable' function. To import specific column from the csv file, you can specify options and select the variable names using 'SelectedVariableNames'.
Refer the below link to know how to create import options object for a csv file.
After extracting data into a matrix, use the 'fft2' function to perform 2D FFT.
I hope this helps.

댓글 수: 3

This is the code I am using it is giving an error.
I want to import only the variable "accel_x" from each file.
This is the error I am getting:
"Error using readtable
All parameters must have an associated value.
Error in Finalfilecsv (line 5)
data{i}=readtable(d(i).name,opts); "
d=dir('*.csv');
n=length(d);
for i=1:n
opts.SelectedVariableNames = {'accel_x'};
data{i}=readtable(d(i).name,opts);
end
Hi Manoj,
I understand that you want to import only the variable "accel_x" from each file.
The reason for the error might be because of different column name. You can run the below code and check if the SelectedVariableNames gives “accel_x” as one of the outputs in the cell array.
opts = detectImportOptions('filename')
opts.SelectedVariableNames
I hope it helps.
Manoj Manoj
Manoj Manoj 2022년 11월 22일
Thank you, it worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2022a

태그

질문:

2022년 11월 16일

댓글:

2022년 11월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by