How do I iteratively create new structure fields?

조회 수: 4 (최근 30일)
James Parkus
James Parkus 2017년 11월 30일
답변: Walter Roberson 2017년 11월 30일
Hello, I am trying to split data logarithmically to do a Fourier analysis. To do this I figured it would be very convenient to store each new data matrix in a structure. So let's say I start with a initial pool of 100000 data points. I want the next data pool to be 10000 and then 1000 and so on. However, I am running into an issue where I cannot tell the script to create new fields according to each iteration through the while loop.
To explain a bit further.
I initially have n = 1. Where n is the iteration number. Then I separate the data I want and store it in a structure, Window.Win1. Then on the next iteration, n = 2, I want to store the new data in a new field, Window.Win2., and so on.
Here is my code,
n = 1;
low(n) = 1;
up(n) = 100000;
hub = up(n) - low(n);
while hub > 0
sprintf('Window.Win%s = Vib_Data(low:up,1)',n);
low(n+1) = low(1) + up(n);
up(n+1) = up(n) + up(n)*10^(-n);
hub = up(n) - low(n);
n = n + 1;
end
I attempted to use a sprintf function but to no avail. I understand this may not be the best way to go about performing this separation so if you have any comments on that fact, please send them my way. I am still learning.
Thank you,
James Emerson Parkus

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 30일
Change
sprintf('Window.Win%s = Vib_Data(low:up,1)',n);
to
Window.(sprintf('Win%d', n)) = Vib_Data(low:up,1);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by