matlab - 使用特定文件名保存矩阵 matlab

标签 matlab save

我正在尝试保存具有特定文件名的 2 列矩阵,但我不断生成相同的错误消息:

Error using save
Must be a string scalar or character vector

我的代码如下所示:

    CustomName = ['TheDataFrom','_', animalname, '-', animalnumber,'-',num2str(stimNumber), num2str(stimType), '.mat']); % the name I want the file to have, changes with different specimens
TheData(:,1) =  codes(index,1);
TheData(:,2) =  times(values,1)); %both of these vectors are the same length

save(CustomName, TheData);

我还尝试通过首先将 TheData 设为空矩阵,将“TheData”变量设为双向量,因此代码看起来像这样,带有额外的行:

 CustomName = ['TheDataFrom','_', animalname, '-', animalnumber,'-',num2str(stimNumber), num2str(stimType), '.mat']); % the name I want the file to have, changes with different specimens
TheData = zeros(length(index), 2) %make a matrix of the right number of rows and columns, comes out as class 'double'
TheData(:,1) =  codes(index,1); %put data into each column
TheData(:,2) =  times(values,1)); 

save(CustomName, TheData);

我只想用一个样本特定名称保存这个矩阵,我不知道为什么我正在做的事情不起作用。请帮忙!

谢谢

最佳答案

您需要指定要保存为字符向量的变量的名称,这意味着您不希望实际将变量本身作为 save 的参数传递。而是创建一个包含要存储的变量名称的字符向量:

save(Customname, 'TheData');

关于matlab - 使用特定文件名保存矩阵 matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54844060/

相关文章:

mongodb - 在 Mongoose 中,Model.find() 和 Model.find().exec() 产生相同的结果。那么为什么还要使用 Model.find().exec() 呢?

C# - Windows 窗体应用程序 - 保存文件

android - 如何将图片保存到文件?

java - 当我尝试从中调用 Java 方法时,Matlab 锁定了 jar 文件

matlab - Octave生成组合子集

matlab - 使用 MATLAB imread 函数读取 URL 图像时指定超时

c++ - 通过 C++ 或 VB.NET 集成 Matlab DLL

matlab - 在 MATLAB 中将一个小矩阵 move 到一个更大的矩阵中

c# - Silverlight XML 保存不会覆盖整个文件

java - 如何在 Java 中有效地管理文件系统上的文件?