Inserting doubles into the field of a struct
조회 수: 14 (최근 30일)
이전 댓글 표시
Wondering if anyone knows how to insert a "double" into a struct. I was trying to use the following code to do it but I keep getting the error "Scalar structure required for this assignment."
Updating.GoodNews = Upda;
댓글 수: 0
채택된 답변
Chunru
2022년 9월 19일
load(websave("Updating.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1129165/Updating.mat"))
load(websave("Upda.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1129170/Upda.mat"))
whos
% Optimism_EMA_Updating is an array of structure
% assignment should be done for struct element
Optimism_EMA_Updating(1).GoodNews = Upda;
Optimism_EMA_Updating(1)
추가 답변 (1개)
Image Analyst
2022년 9월 19일
It's because Updating is a structure array so you need to put Upda into a new structure in the array. This works, where I append Upda to the existing array:
% Load mat files into structures.
s1 = load('Updating.mat')
s2 = load("Upda.mat")
% Extract variables from the structures.
Optimism_EMA_Updating = s1.Optimism_EMA_Updating
Upda = s2.Upda
% Append Upda as a new structure at the end of the structure array
Optimism_EMA_Updating(end+1).SubID = Upda
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!