How can I create a function that updates a structure whose input is that structure?

조회 수: 2 (최근 30일)
I have the following section of code that I'd like to convert into a function:
count = 1;
for j = 1:length(data_raw{1}.test_date_time)
if data_raw{1}.test_date_time(j) == ...
data_raw{1}.test_date_time(1) + 1
data_raw{2}.test_date_time_single_second_model(count) = ...
data_raw{1}.test_date_time(j);
count = count + 1;
else
end
end
data_raw{2}.test_date_time_single_second_model = ...
data_raw{2}.test_date_time_single_second_model';
The inputs are fields in a the structure data_raw (so, data_raw{1}.test_date_time). The output is the structure data_raw with the new field test_date_time_single_second_model (so, data_raw{2}.test_date_time_single_second_model).
I've looked through previous community responses for similar entries, but I haven't figured out how to create the function I need.
Will someone please help me?

채택된 답변

Image Analyst
Image Analyst 2021년 10월 12일
Just have the output be the input:
To call
data_raw = AlterStructure(data_raw );
To define
function data_raw = AlterStructure(data_raw)
count = 1;
for j = 1:length(data_raw{1}.test_date_time)
if data_raw{1}.test_date_time(j) == ...
data_raw{1}.test_date_time(1) + 1
data_raw{2}.test_date_time_single_second_model(count) = ...
data_raw{1}.test_date_time(j);
count = count + 1;
else
end
end
data_raw{2}.test_date_time_single_second_model = ...
data_raw{2}.test_date_time_single_second_model';

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by