简体   繁体   English

八度:使用子文件夹中存储的文件名创建.csv文件

[英]Octave: create .csv files with varying file names stored in a sub folder

I have multiple arrays with string data. 我有多个带有字符串数据的数组。 All of them should be exported into a .csv file. 所有这些都应导出到.csv文件中。 The file should be saved in a subfolder. 该文件应保存在子文件夹中。 The file name is variable. 文件名是可变的。

I used the code as follows: 我使用的代码如下:

fpath = ('./Subfolder/');
m_date = inputdlg('Date of measurement [yyyymmdd_exp]');
m_name = inputdlg('Characteristic name of the expteriment');
fformat = ('.csv');

fullstring = strcat(fpath, m_date,'_', m_name, fformat);
dlmwrite(fullstring,measurement); 

However, I get an error that FILE must be a filename string or numeric FID 但是,我收到一个错误,指出FILE必须是文件名字符串或数字FID

What's the reason? 什么原因?

Best Andreas 最佳安德烈亚斯

What you are asking to do is fairly straightforward for Matlab or Octave. 对于Matlab或Octave,您要执行的操作非常简单。 The first part is creating a file with a filename that changes. 第一部分是创建文件名更改的文件。 the best way to do this is by concatenating the strings to build the one you want. 最好的方法是将字符串串联起来以构建所需的字符串。

You can use: fullstring = strcat('string1','string2') 您可以使用: fullstring = strcat('string1','string2')

Or specifically: filenameandpath = strcat('./Subfolder/FixedFileName_',fname) 或者具体来说: filenameandpath = strcat('./Subfolder/FixedFileName_',fname)

note that because strings are pretty much just character arrays, you can also just use: 请注意,因为字符串几乎只是字符数组,所以您也可以使用:

fullstring = ['string1','string2'] fullstring = ['string1','string2']

now, if you want to create CSV data, you'll first have to read in the file, possibly parse the data in some way, then save it. 现在,如果要创建CSV数据,则首先必须读取文件,可能以某种方式解析数据,然后将其保存。 As Andy mentioned above you may just be able to use dlmwrite to create the output file. 如上面的Andy所述,您也许可以使用dlmwrite创建输出文件。 We'll need to see a sample of the string data to have an idea whether any more work would need to be done before dlmwrite could handle it. 我们将需要查看字符串数据的样本,以了解在dlmwrite处理它之前是否需要做更多的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM