필터 지우기
필터 지우기

Scalar structure required for this assignment.

조회 수: 255 (최근 30일)
Luca Re
Luca Re 2023년 6월 2일
댓글: Matt J 2023년 6월 5일
Sis =
1×82 struct array with fields:
Name
dailyprof
cc
gapp
ttrange
Ntradess
>> class(D_(:,2))
ans =
'cell'
>> Sis.On=D_(:,2);
Scalar structure required for this assignment.
hi ..how do I add it as a field?
  댓글 수: 2
James Tursa
James Tursa 2023년 6월 2일
편집: James Tursa 2023년 6월 2일
What is the size of D_? Are you trying to add each cell element of D_(:,2) as a struct field in Sis?
Luca Re
Luca Re 2023년 6월 3일
Yes...i want to add cell array in structure a structure can contain different data types...double string..

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

채택된 답변

Matt J
Matt J 2023년 6월 2일
편집: Matt J 2023년 6월 2일
Your intention with the code is not clear, but here is one possibility,
[Sis.On]=deal(D_{:,2});
  댓글 수: 4
Luca Re
Luca Re 2023년 6월 5일
can you help me in the last questions? thanks
Matt J
Matt J 2023년 6월 5일
You seem to have deleted your follow-up questions, but it's preferable anyway to put those in a new thread.

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

추가 답변 (2개)

James Tursa
James Tursa 2023년 6월 2일
편집: James Tursa 2023년 6월 2일
This?
[Sis.On] = D_{:,2};
  댓글 수: 1
Luca Re
Luca Re 2023년 6월 3일
no...it give me same error
It's correct to use function deal!

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


VBBV
VBBV 2023년 6월 2일
Sis.On={D_(:,2)};
  댓글 수: 3
Luca Re
Luca Re 2023년 6월 3일
no...it give me same error
It's correct to use function deal!
VBBV
VBBV 2023년 6월 3일
편집: VBBV 2023년 6월 3일
As you want cell array as struct field, it works well without error, See below example ...
D_ = {rand(12,2),rand(12,1)}
D_ = 1×2 cell array
{12×2 double} {12×1 double}
class(D_)
ans = 'cell'
% cell array as struct field
Sis.On = {D_(:,2)}
Sis = struct with fields:
On: {{1×1 cell}}
Sis.On{:}{:}
ans = 12×1
0.2029 0.1979 0.5255 0.7647 0.0654 0.0657 0.7028 0.2226 0.2164 0.5529

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by