How to store a string of n elements as one element of a matrix

조회 수: 1 (최근 30일)
Gustavo
Gustavo 2020년 3월 26일
댓글: Peng Li 2020년 3월 27일
I have a function wich give me an array of elements like Nff=[5 0 5 0] and I want to insert Nff into a matrix N(i,j)=Nff. It can be numeric or string. It`s only important to me to store the array in the same row of the others elements 'i' and 'j' as one element of the matrix.

답변 (1개)

Peng Li
Peng Li 2020년 3월 26일
You may want to try a cell array instead? N{i, j} = Nff;
  댓글 수: 3
Gustavo
Gustavo 2020년 3월 26일
I need to keep the numeric numbers in the main matrix. I want to do something like
Nff(i,j)=Nff which change at each iteraction, then I want to insert then into a numeric matrix but I can consider Nff is number, cell, string, whatever
pat=[1 2 3 Nff 4 5 6; 2 1 4 Nff 5 6 1; .....]
pat=[1 2 3 '[5 0 5 0]' 4 5 6; 2 1 4 '[11 12 11 12 11 12]' 5 6 1; .....]
Peng Li
Peng Li 2020년 3월 27일
Sorry I don't quite understand your question. It's tricky to extend a matrix this way in a loop as you add a block during one loop process to one dimension, the size changes and it conflicts with other dimension. For example, in your example above, you add four element in the first row, it's gonna stop because in this matrix pat, there are only 6 columns in the second row while you force it to have 10 elements in the first row. It's not allowed, and there is no way that you add 6 elements to the second row. They have to be consistent.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by