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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!