MATLAB - 索引超出矩阵维度
您好,我有矩阵问题。
我有许多行数不同但列数相同(1 列)的 .txt 文件,
e.g. s1.txt = 1234 rows
s2.txt = 1200 rows
s2.txt = 1100 rows
我想合并这三个文件。由于它有不同的行..当我将其写入新文件时,我收到此错误=索引超出矩阵维度。
我该如何解决这个问题? 。
Hi I have problem with matrix..
I have many .txt files with different number of rows but have the same number of column (1 column)
e.g. s1.txt = 1234 rows
s2.txt = 1200 rows
s2.txt = 1100 rows
I wanted to combine the three files. Since its have different rows .. when I write it to a new file I got this error = Index exceeds matrix dimensions.
How I can solved this problem? .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以简单地通过堆叠来组合三个矩阵:假设
s1
等是您读入的矩阵,您可以像这样创建一个新矩阵:snew = [s1; s2; s3];
如果您只需要执行一次,您还可以使用
[]
样式堆叠而不创建新的矩阵变量。You can combine three matrices simply by stacking them: Assuming that
s1
, etc are the matrices you read in, you can make a new one like this:snew = [s1; s2; s3];
You could also use the
[]
style stacking without creating the new matrix variable if you only need to do it once.您提供的信息太少,无法准确诊断您的问题。也许您已将文件中的数据加载到工作区中的变量中。也许
s1
有 1 列和 1234 行,等等。然后您可以将变量连接成一个列向量,如下所示:并使用
save()
将其写入文件陈述。这有帮助吗?
You have provided far too little information for an accurate diagnosis of your problem. Perhaps you have loaded the data from your files into variables in your workspace. Perhaps
s1
has 1 column and 1234 rows, etc. Then you can concatenate the variables into one column vector like this:and write it out to a file with a
save()
statement.Does that help ?
让我假设这个问题与您的另一个 问题有关,并且您希望按列组合这些矩阵,在数据较少的列中留下空值。
在这种情况下,此代码应该可以工作:
该代码假设每个文件中都有一列,否则它将无法工作。
Let me make an assumption that this question is connecting with your another question, and you want to combine those matrices by columns, leaving empty values in columns with fewer data.
In this case this code should work:
The code assumes you have one column in each file, otherwise it will not work.