Getting error while saving the data into csv file?

12 Ansichten (letzte 30 Tage)
muhammad choudhry
muhammad choudhry am 17 Jun. 2022
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));

Akzeptierte Antwort

Karim
Karim am 17 Jun. 2022
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 Kommentar
muhammad choudhry
muhammad choudhry am 17 Jun. 2022
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 );

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by