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

조회 수: 3 (최근 30일)
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

채택된 답변

Image Analyst
Image Analyst 2021년 9월 23일
편집: Image Analyst 2021년 9월 23일
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.

추가 답변 (0개)

카테고리

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