使用特定文件名Matlab保存矩阵

时间:2019-02-23 17:19:19

标签: 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);

我只想用一个标本特定的名称保存这个矩阵,我对为什么我的工作不起作用没有想法。请帮忙!

谢谢

1 个答案:

答案 0 :(得分:1)

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

save(Customname, 'TheData');