How can I write a 2D array into a CSV file
古いコメントを表示
I have read an array from a csv file and done some calculations on that. After that, I want to save the array excactly like the CSV file I read.I would be thankful if anyone could help me with this .I have also attached a sample file. thank You so much
sample=readmatrix('71.csv');
Blank=readmatrix('Blank.csv');
x=sample(1,2:end);
y=sample(2:end,1);
RamanArea=5275.6715;
data=sample(2:end,2:end);
dataBlank=Blank(2:end,2:end);
[numRows,numCols] = size(data);
data=data-dataBlank;
for k = 1:numRows
for l = 1:numCols
data(k,l)=data (k,l)/RamanArea;
end
end
for i = 1:numRows
for j = 1:numCols
if (data(i,j)<=0)
data(i,j)=NaN;
end
end
end
xCSV=numRows+1;
yCSV=numCols+1;
xsvArray=csvArray(xCSV,yCSV);
csvArray(2:end,1)=x;
csvArray(1,2:end)=y;
csvwrite('file.csv',csvArray);
csvwrite('file.csv',x,1,0);
figure();
surf(x,y,data);
colorbar();
3 件のコメント
Walter Roberson
2022 年 2 月 17 日
Normally I would say just use writematrix(). However you said "exactly" like the CSV file you read, and the first field of that example file is missing (file starts with a comma). Is the implication that you want missing fields to be output as empty? If so then the NaN values you write in, are those to count as missing values for the purpose of determining whether to write emptiness or not?
Behrad Ze
2022 年 2 月 17 日
Behrad Ze
2022 年 2 月 17 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!