Getting error while saving the data into csv file?
조회 수: 12 (최근 30일)
이전 댓글 표시
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
채택된 답변
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.
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 );
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!