Scalar structure required for this assignment.

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 Kommentare

James Tursa
James Tursa am 2 Jun. 2023
Bearbeitet: James Tursa am 2 Jun. 2023
What is the size of D_? Are you trying to add each cell element of D_(:,2) as a struct field in Sis?
shamal
shamal am 3 Jun. 2023
Yes...i want to add cell array in structure a structure can contain different data types...double string..

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Matt J
Matt J am 2 Jun. 2023
Bearbeitet: Matt J am 2 Jun. 2023

2 Stimmen

Your intention with the code is not clear, but here is one possibility,
[Sis.On]=deal(D_{:,2});

4 Kommentare

shamal
shamal am 3 Jun. 2023
thanks you...now it's ok!
Matt J
Matt J am 5 Jun. 2023
thanks you...now it's ok!
I'm glad, but please Accpet-click the answer to indicate that it solved your problem.
shamal
shamal am 5 Jun. 2023
can you help me in the last questions? thanks
Matt J
Matt J am 5 Jun. 2023
You seem to have deleted your follow-up questions, but it's preferable anyway to put those in a new thread.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

James Tursa
James Tursa am 2 Jun. 2023
Bearbeitet: James Tursa am 2 Jun. 2023

0 Stimmen

This?
[Sis.On] = D_{:,2};

1 Kommentar

shamal
shamal am 3 Jun. 2023
no...it give me same error
It's correct to use function deal!

Melden Sie sich an, um zu kommentieren.

VBBV
VBBV am 2 Jun. 2023

0 Stimmen

Sis.On={D_(:,2)};

3 Kommentare

VBBV
VBBV am 2 Jun. 2023
Since D_(:,2) belongs to class cell
shamal
shamal am 3 Jun. 2023
no...it give me same error
It's correct to use function deal!
VBBV
VBBV am 3 Jun. 2023
Bearbeitet: VBBV am 3 Jun. 2023
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 2 Jun. 2023

Kommentiert:

am 5 Jun. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by