How do I iteratively create new structure fields?

4 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by