【问题标题】:Vector dimensions and variable display矢量尺寸和可变显示
【发布时间】:2018-02-14 22:23:05
【问题描述】:

您好这是一个关于Matlab如何显示某些变量的问题,具体取决于包含的维数。当我生成randn(10,2) 时,我在工作区窗口中得到一个 10X2 的表格,很容易直接从这里复制粘贴到 excel 中。但是,当我执行randn(10,2,1) 时,Matlab 会在工作区中创建一些看起来像文本文件的东西。例如,当您拥有randn(1000,2,1) 时,复制数据可能会很痛苦。为什么 Matlab 会这样做?

对于上下文 - 我想为多个资产和多个模拟“预生成”(如果有这样的话)一组随机数;因此我使用randn(NumSteps,NumAssets,NumSimulations)。我确信有更好的方法来做到这一点......所以我们总是很感激你的建议。

【问题讨论】:

  • 既然可以将其直接导出到 Excel 文件中,为什么还要复制和粘贴? xlswrite
  • randn(10,2,1)randn(10,2) 完全相同,MATLAB 会删除尾随的单例维度。也许你的意思是randn(10,1,2)
  • 公平点,我只是好奇它为什么会这样......

标签: matlab random


【解决方案1】:

在我看来,xlswrite 可以解决您的问题。

试试这个:

clc; clear;
%%Generate Data
NumSteps=10; NumAssets=10; NumSimulations=5;
RandData=randn(NumSteps,NumAssets,NumSimulations);

%%Output Data into a Excel File
for i=1:NumSimulations
xlswrite('Data.xls',RandData(:,:,i),['Sheet',num2str(i)])
end;

更改变量的值,我们可以在sheet1SheetN 中拥有NumSteps x NumAssetsNumSimulation 矩阵。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多