gpt4 book ai didi

excel - 如何使用Matlab将数据保存到Excel表格中?

转载 作者:行者123 更新时间:2023-12-03 02:03:41 28 4
gpt4 key购买 nike

我想将数据以表格形式保存在 Excel 工作表中。它应该看起来像:

Name |  Age |   R_no |  Gpa
Adnan | 24 | 18 | 3.55
Ahmad | 22 | 12 | 3.44
Usman | 23 | 22 | 3.00

每次执行文件 classData.m 时,都会在下面添加一行。就像我想添加下一行一样

约翰 | 21 | 21 44 | 44 3.53

变量 n='john', ag=22, rn=44, gp=3.53

最佳答案

使用@Tom给出的代码

如果文件尚不存在,它将创建一个新文件;如果存在,它将附加下面的行。

filename='Features.xlsx';
N='Adnan'; a=22; roll=22; gpa=3.55;
fileExist = exist(filename,'file');
if fileExist==0
header = {'Name', 'age ','roll' , 'gpa'};
xlswrite(filename,header);


else

[~,~,input] = xlsread(filename); % Read in your xls file to a cell array (input)
new_data = {N, a,roll , gpa}; % This is a cell array of the new line you want to add
output = cat(1,input,new_data); % Concatinate your new data to the bottom of input
xlswrite(filename,output); % Write to the new excel file.

end

关于excel - 如何使用Matlab将数据保存到Excel表格中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25314739/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com