Getting error while saving the data into csv file?
10 views (last 30 days)
Show older comments
muhammad choudhry
on 17 Jun 2022
Commented: muhammad choudhry
on 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));
0 Comments
Accepted Answer
Karim
on 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.
Anyhow like i answerd to your earlier question in How would I take the mean of each row from column_13 of 79 csv files? - (mathworks.com)
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 );
More Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!