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

2 vues (au cours des 30 derniers jours)
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
%H(struct).
%Thanks in advance

Réponse acceptée

Image Analyst
Image Analyst le 23 Sep 2021
Modifié(e) : Image Analyst le 23 Sep 2021
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
end
end
end
H
% 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.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by