MATLAB:写字符串到Excel [英] MATLAB: Write string into Excel

查看:338
本文介绍了MATLAB:写字符串到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写系数的数组下1列(A1)的Excel文件。这里是我的代码片段:

I am trying to write an array of coefficients into an Excel file under 1 column (A1). Here is my snippet:

    filename = 'cheby2coefs.xlsx';

for Order = 1:1 
    fprintf('This is');
    disp(Order);

    [b,a] = cheby2(Order, 20, 300/500);
    disp([b,a]);
    %xlswrite(filename,{'Order ',Order},'A1'); %string
    xlswrite(filename,'b','A1');  %string
    xlswrite(filename,b');
    xlswrite(filename,'a');       %string
    xlswrite(filename,a');
end

这是我的目标的输出是这样的:

The output that i aim for is something like this:

不过,我的code只是不断创建其他表。什么是实现这个正确的方法是什么?

However, my code just keeps creating other sheets. What is the proper way to implement this?

推荐答案

问题是在 xlswrite 行:

xlswrite 文件:

xlswrite(文件名,A,表)写入指定的工作表中。

xlswrite(filename,A,sheet) writes to the specified worksheet.

这意味着你正在写字符串'B',以表A1与 xlswrite(文件名,'B','A1');

That means you are writing string 'b' to sheet 'A1' with xlswrite(filename,'b','A1');

xlswrite(文件名,A)写入数组A到Excel中的第一个工作表
  文件,文件名,开始在单元格A1。

xlswrite(filename,A) writes array A to the first worksheet in Excel file, filename, starting at cell A1.

您其实并不需要做任何事情来开始在A1写作。假设b是行向量:

You actually do not need to do anything to start writing at A1. Assuming b is a row vector:

xlswrite(filename,b');

为你写,应该足够了。

as you have written, should suffice.

如果要指定表和列,您可以使用

If you want to specify sheet and column you can use

xlswrite(filename,A,sheet,xlRange)


更新:我现在不能试试这个权利,但我认为它应该工作。


Update: I cannot try this right now but I think it should work.

您可以计算 A B 订单并写到这样一个xls文件:

You can calculate a and b for every order and write them to an xls file like this:

r = 1; % row number
str = {'a', 'b'};
order = [1 3 5]; % The orders you want to calculate a and b with
for idx = 1:size(order, 2)
    [b,a] = cheby2(order(idx), 20, 300/500); % I do not know about second 
                                             % and third parameters, you should 
                                             % check them.
    vals = [a; b]; % assuming they are row vectors
    cellName = strcat('A', r);
    orderName = strcat('Order ', order(idx));
    xlswrite(filename, orderName, 1, cellName)
    r = r + 1;
    for jdx=1:2
        cellName = strcat('A', r);
        xlswrite(filename, str{jdx}, 1, cellName);
        r = r + 1;
        cellName = strcat('A', r);
        xlswrite(filename, vals(jdx, :), 1, cellName);
        r = r + size(vals, 2);
    end
end

这篇关于MATLAB:写字符串到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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