Info

This question is closed. Reopen it to edit or answer.

How can I save different values in different fields of my structure?

1 view (last 30 days)
I have a structure and I want to pull temperature data for specific dates. I wrote a code that loop trough the structure, but my idea was to created another structure that save those specific values. Because more than one field of my structure has temperature at the same dates and I will like to keep track of where those values where/ Right now is saving everything in one variable called A.
Here is an example of my code:
timeofproject ={'07192013','09062013','03272014'};
copy = mooring; %This is my structure
month = 3;
day = 1;
year = 2014;
l=1;
for i = 4:-1:1;
for j = 1:length(timeofproject);
for ii=2:4;
fieldName = fieldnames(copy.(['T', num2str(i)]));
fieldName = fieldName{ii};
fieldName = fieldName(6:end);
for jj = 1:3
if fieldName == timeofproject{jj}
break
end
end
pCount = fieldnames(copy.(['T', num2str(i)]).(['data_', fieldName]));
pCount = length(pCount);
for k=1:pCount;
[m,n] = size(copy.(['T',num2str(i)]).(['data_', fieldName]).(['P',num2str(k)]).Data);
for kk = 1:m;
if (copy.(['T',num2str(i)]).(['data_', fieldName]).(['P',num2str(k)]).Data(kk,3) == year) & ...
(copy.(['T',num2str(i)]).(['data_', fieldName]).(['P',num2str(k)]).Data(kk,1) == month)& ...
(copy.(['T',num2str(i)]).(['data_', fieldName]).(['P',num2str(k)]).Data(kk,2) == day);
A(l,1:7) = copy.(['T',num2str(i)]).(['data_',fieldName]).(['P',num2str(k)]).Data(kk,1:7);
l=l+1;
end
end
end
end
end
end
Thanks

Answers (0)

Community Treasure Hunt

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

Start Hunting!