Getting error while saving the data into csv file?

조회 수: 27 (최근 30일)
muhammad choudhry
muhammad choudhry 2022년 6월 17일
댓글: muhammad choudhry 2022년 6월 17일
Hi,
I am using the code below to extract the data from the csv files but I am having trouble saving the data into separate csv file.
Code:
close all; clear all; clc;
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side_LSB\Length\DesignPoint\110_outlet';
Q = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side_LSB\Length\DesignPoint';
files = dir(fullfile(P,'*.csv'));
for ii = 1:length(files)
data = readtable(fullfile(files(ii).folder,files(ii).name))
x(:,ii)= data(:,13)
end
csvwrite(fullfile(Q, 'Design110_columns.csv'),x(:,ii));
Error:
Check for missing argument or incorrect argument data type in call to function 'real'.
Error in csvwrite (line 47)
throw(e)
Error in Extracting_Column (line 10)
csvwrite(fullfile(Q, 'Design110_columns.csv'),x(:,ii));

채택된 답변

Karim
Karim 2022년 6월 17일
Why do you not append this to the 5 questions you asked earlier? You make it very difficult to link them to each other.
It would help if you changed the 'table' into a numeric array, a quick fix is:
csvwrite( fullfile(Q, 'Design110_columns.csv') , table2array( x(:,ii) ) );
However, if i understand your earlier questions correctly you actually want the mean of the files saved into this new file so try the following:
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side_LSB\Length\DesignPoint\110_outlet';
S = dir(fullfile(P,'*.csv'));
N = natsortfiles({S.name});
TurbulentFluctuationArray_Mean=zeros(numel(N), 1);
col_13_data = zeros(48,numel(N))
for i = 1:numel(N);
data = readtable( fullfile(P, N{i}) ); % read the csv files
col_13_data(:,i) = table2array( data(:,13) ); % get the 13th column of each file
end
col_13_mean = mean(col_13_data ,2 ); % get the mean value for each row, over the files
csvwrite( fullfile(Q, 'Design110_columns.csv') , col_13_mean );
  댓글 수: 1
muhammad choudhry
muhammad choudhry 2022년 6월 17일
Thanks alot! yea I kind of messed up the code and ended up asking different thing for the same solution.One question tho. why did you write 2 in the line below? what does it do?
col_13_mean = mean(col_13_data ,2 );

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by