matrix contain index track

6 ビュー (過去 30 日間)
Mingcheng Tsai
Mingcheng Tsai 2019 年 10 月 10 日
コメント済み: thoughtGarden 2019 年 10 月 10 日
Hi, all.
Is it possible to put a matrix with a index array in matlab
like and after some operations, I would like to have
which is a incresing matrix.
Thank you so much

採用された回答

thoughtGarden
thoughtGarden 2019 年 10 月 10 日
The only way I'm aware of you have arrays within another indexed structure is to use cells. I'm not sure exactly what you are trying to do, but something like this should get you started:
I{1,1} = [1,3];
I{2,1} = [2,3];
I{1,2} = [1,4];
I{2,2} = [2,4];
This builds your initial cell array. Do what you want after that. Note that when using cells, the individual arrays are not linked by any means, so they can be different sizes and contain completely different data. You will have to control how each array grows and changes.
  2 件のコメント
Mingcheng Tsai
Mingcheng Tsai 2019 年 10 月 10 日
Thank you for the answer.
I think cell is the only choice for me if I have a unfixed matrix operation.
thoughtGarden
thoughtGarden 2019 年 10 月 10 日
If you found this answer to be correct, please accept it. Otherwise, please add aditional comments so that it may be improved.

サインインしてコメントする。

その他の回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 10 日
Sure:
I = [1, 3, 1, 4;
2, 3, 2, 4];
% Then operate away...
But it is very unclear if that is what you really want. Does your grouping in the matrixes indicate that you have some meaning with (1,3) (1,4) (2,3) and (2,4) as pairs of indices? If so you might want to make the matrix a 3-D array:
I(:,:,2) = [3,4;
3,4];
I(:,:,1) = [1,1;
2 2];
Then you could potentially grow that array in in the third dimension as you go along - which you seem to indicate with your second array I where you have the elements grouped in triplets?
If you need to go completely arbitrary with varying length of index-lists, cell-arrays might give you a solution:
I{1,1} = [1,3];
I{1,2} = [1,4];
I{2,1} = [2,3];
I{2,2} = [1 4 3 576 1]; % For example
HTH
  1 件のコメント
Mingcheng Tsai
Mingcheng Tsai 2019 年 10 月 10 日
Thank you so much and I will consider the method of cell array.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by