是否可以在Matlab上使用行具有不同#行的矩阵? [英] Is it possible to make a matrix with rows that have different #rows on Matlab?

查看:165
本文介绍了是否可以在Matlab上使用行具有不同#行的矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个矩阵或另一种作为行的变量.事实是,第一行可以有10个数字(列),第二行只有3个,第三个是5,依此类推... 那可能吗?以及如何?

I want to make a matrix, or another kind of variable that as rows. The thing is that with the first row there can be 10 numbers(columns), and the second only 3, and the third 5, and so on... Is that possible? And how?

我需要通过一个矩阵,然后存储数字.这是一个m×2的矩阵.我正在用for循环进行遍历.像这样:

I need to through a matrix, then store the numbers. It's a m-by-2 matrix. I'm going through it with a for loop. Like so:

rows = size (mtx, 1);
for i = 1 : rows
    var = m (i, :);
    if m(2) is in A{something}
        if m(3) is in A{something}
            continue (ignore)
        else
            store m(3) in A{something}
        end
    else
        if m(3) is in A{something}
            store m(2) in A{something}
        else store both m(2) and m(3) in A{Newsomething}
        end
    end
end

推荐答案

不是作为矩阵,而是作为单元格数组,是的:

Not as a matrix, but as a cell array, yes:

A{1} = [1 2 3 4 5 6 7 8 9 10];
A{2} = [1 2 3];
A{3} = [1 2 3 4 5];

>> A
A =
{
  [1,1] =

      1    2    3    4    5    6    7    8    9   10

  [1,2] =

     1   2   3

  [1,3] =

     1   2   3   4   5

}

这篇关于是否可以在Matlab上使用行具有不同#行的矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆