How to add a new array in the structure?

조회 수: 4 (최근 30일)
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2021년 8월 11일
댓글: Yazan 2021년 8월 12일
Let say I have this structure ( vehicle.genset_model) where inside this structure I have vehicle.genset_model.drag=[4;5;6;7;8;9;10]. This file is saved as mat file. In this file I want to create a new array that should be in the same structure (vehicle.genset_model) but with the extension temperature i.e., vehicle.genset_model.Temperature=[25;28;31;34;37;40;43]

채택된 답변

Yazan
Yazan 2021년 8월 11일
clc, clear
vehicle.genset_model.drag = [4; 5; 6; 7; 8; 9; 10];
% save structure array in 'data.mat'
save('data.mat', 'vehicle');
clear
% load data.mat
load('data.mat');
% add a new field
vehicle.genset_model.Temperature = [25; 28; 31; 34; 37; 40; 43];
% save new structure array
save('data.mat', 'vehicle');
clear
  댓글 수: 2
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2021년 8월 12일
When I do this I get this error Unrecognized property 'Temperature' for class 'genset'.
Yazan
Yazan 2021년 8월 12일
On which line, you get this error? The code is pretty simple and it works.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by