필터 지우기
필터 지우기

add cell to arraycell

조회 수: 27 (최근 30일)
Luca Re
Luca Re 2024년 7월 20일 18:45
댓글: Luca Re 2024년 7월 20일 19:24
i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent.

답변 (2개)

Milan Bansal
Milan Bansal 2024년 7월 20일 19:18
편집: Milan Bansal 2024년 7월 20일 19:19
Hi Luca Re,
I understand that you wish to add a new row in the cell array "oldList" whole first element is "sistema" but are facing issues with it.
The variable "oldList" in the attached .MAT file is a cell array with 3 rows and 15 columns, where as the variable "sistema" is just a string. Hence concatenating them directly is not possible due to inconsistent dimensions. However you can add the "sistema" in the "oldList" in a new row as shown in the code snippet below:
load("matlab_cell.mat")
newRow = cell(1, 15);
newRow{1, 1} = sistema;
% Concatenate newRow with oldList to create newList
newList = [newRow; oldList]
newList = 4x15 cell array
Columns 1 through 10 {["ES_Live_MPV ..."]} {0x0 double} {0x0 double} {0x0 double} {0x0 double } {0x0 double } {0x0 double} {0x0 double} {0x0 double} {0x0 double} {'ES_Live_MPV Es...'} {[ 1]} {'ES' } {'On Micro'} {'2023/12/01'} {'From instrument'} {[ 0]} {'Trend' } {'Multiday'} {'No' } {'ES_Live_MPV Es...'} {[ 1]} {'ES' } {'On Micro'} {'2024/05/01'} {'From instrument'} {[ 0]} {'Trend' } {'Intraday'} {'No' } {'ES_Live_MPV Es...'} {[ 1]} {'ES' } {'On Micro'} {'2008/01/01'} {'From instrument'} {[ 6]} {'Trend' } {'Intraday'} {'No' } Columns 11 through 15 {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]}
Hope this helps!
  댓글 수: 1
Luca Re
Luca Re 2024년 7월 20일 19:24
I realized now that they have different sizes :(

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


LeoAiE
LeoAiE 2024년 7월 20일 19:03
Not sure if I understand your question here but I think you can do this:
oldList = {struct('field1', 1), struct('field1', 2)};
sistema = struct('field1', 3);
% Convert sistema to a cell and concatenate
newList = [{sistema}, oldList];

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by