Double vs. Cell "Undefined function 'plus' for input arguments of type 'cell' "

조회 수: 6 (최근 30일)
Sam136
Sam136 2015년 6월 30일
댓글: Star Strider 2015년 6월 30일
In my code, I have two variables (inp.W{9} & inp.W{10}) which seems to be double (when I remove semicolon, this is shown in command Window: ans = [1x10 double]). However when I try to add these two variables, I get this error:
Undefined function 'plus' for input arguments of type 'cell'.
Error in truck (line 21) inp.W{9}+inp.W{10}

답변 (2개)

Star Strider
Star Strider 2015년 6월 30일
Without having them to experiment with and provide more specific code, I would use cell2mat to convert them first:
W9 = cell2mat(inp.W{9});
W10 = cell2mat(inp.W{10});
Result = W9 + W10;
  댓글 수: 4
Sam136
Sam136 2015년 6월 30일
I'd like to give more information to get better help, but I really don't know how to copy a long code with more than 2000 lines here.
Star Strider
Star Strider 2015년 6월 30일
It’s not code but your data that we need to determine your problem.
First, save your ‘inp’ structure as a .mat file, then attach it using the ‘paperclip’ icon.

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


Walter Roberson
Walter Roberson 2015년 6월 30일
When you see
[1x10 double]
instead of numbers, then you are looking at a cell rather than a numeric array. Use
inp.W{9}{1}+inp.W{10}{1}
  댓글 수: 1
Sam136
Sam136 2015년 6월 30일
I get same error as previous comment "Attempt to reference field of non-structure array"

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

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by