如何使用Matlab在Excel工作表中保存数据? [英] how to Save Data in Excel Sheet using Matlab?

查看:75
本文介绍了如何使用Matlab在Excel工作表中保存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据保存为Excel工作表中的表格形式.看起来应该像这样:

I want to save my data in form of table in Excel Sheet. It should look like:

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

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

Every time when I will execute my file classData.m , A row will be added below. like I want to add next row as

john |21 |44 |3.53

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

variable n='john', ag=22, rn=44, gp=3.53

推荐答案

使用 @Tom

Using code given by @Tom

如果尚不存在,它将创建一个新文件,如果存在,则将添加以下行.

It will create a new file if it doesn't already exist, and if it does exist, then it will append the row below.

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

这篇关于如何使用Matlab在Excel工作表中保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆