MATLAB Answers

How to write a value of type double(vector) into a cell in a struct

27 views (last 30 days)
Laxmi Akshaya Thela
Laxmi Akshaya Thela on 23 Sep 2021 at 21:12
Commented: Laxmi Akshaya Thela on 24 Sep 2021 at 14:11
H = setfield(H, {1,5}, 'SOC', {1} ,0.8)%I wanted to write value into H(1).SOC in the first cell of field SOC in H(struct)
H(1).SOC{1,1} = 0.8 %I used these two statements but I wasnt able to write values into H(1).SOC vector
%Please suggest me how to write values into SOC(for four rows) of
%Thanks in advance

Accepted Answer

Image Analyst
Image Analyst on 23 Sep 2021 at 21:23
Edited: Image Analyst on 23 Sep 2021 at 21:24
Do you mean like this:
% Make sample H structure array.
for k = 1 : 7
for col = 1 : 3
for row = 1 : 4
H(k).SOC{row, col} = rand
% Now we have an H and we can begin.
% Take the first structure, H(1), and make the SOC field of it be a cell with 0.8 in it rather than the original array.
H(1).SOC(:) = {0.8}
If not, show what you'd like for H in the output.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by