Concatenate integer to variable name

14 views (last 30 days)
Hi, I would like to concatenate the number of the corresponding level to the cell arrays I create. This is what I have tried so far along with other things but nothing seems to work.
for j= 1:230
for i=1:8
for lvl = 3:5
strcat([haar_decomp_ext{j,i}, haar_coeff_num_ext{j,1}],lvl) = wavedec(Ext{j}(:,i+1),lvl,'haar');
end
end
end
Thanks in advance.
  8 Comments
Ioannis Agalliadis
Ioannis Agalliadis on 30 Jun 2017
Edited: Ioannis Agalliadis on 30 Jun 2017
Every column belongs to a different channel and I have 8 columns of them. The first column is the time. The number of rows is different because the time of the movement that I am investigating varies. That means, that I have a variable number of rows always. Now, as I see that storing these data to cell arrays would make the work more difficult I was wondering what if I joined all the data of these cell arrays to 8 vectors which will represent my channels. What is your opinion on that? Would work better?
dpb
dpb on 30 Jun 2017
As above, it depends on what you've left out...what do you want/need to do with the data when you've gotten it?
If each of these is an independent event, then it may make sense to keep them segregated by using the cell array for each.
But, as outlined, that can still be so but if you're just analyzing each in sequence, then there's not necessarily any reason to keep them all in memory so might as well just use the 2D array for each then proceed to the next.
Still not enough detail to know...

Sign in to comment.

Accepted Answer

Jan
Jan on 30 Jun 2017
Edited: Jan on 30 Jun 2017
Result = cell(230, 8, 3);
for j= 1:230
for i=1:8
for lvl = 3:5
Result{j, i, lvl - 2} = wavedec(Ext{j}(:,i+1), lvl, 'haar');
end
end
end
Or if the output of wavedec is a scalar:
Result = zeros(230, 8, 3);
...
Result(j, i, lvl - 2) = wavedec(Ext{j}(:,i+1), lvl, 'haar');
...
If you have a really good reason to hide the indices in the names of the variables (and I'm convinced that this is rarely useful):
for j= 1:230
for i=1:8
for lvl = 3:5
Name = sprintf(%s_%s_%d', haar_decomp_ext{j,i}, haar_coeff_num_ext{j,1}, lvl);
Result.(Name) = wavedec(Ext{j}(:,i+1), lvl, 'haar');
end
end
end

More Answers (1)

Steven Lord
Steven Lord on 30 Jun 2017
"Every column belongs to a different channel and I have 8 columns of them. The first column is the time. The number of rows is different because the time of the movement that I am investigating varies. That means, that I have a variable number of rows always."
If you're using release R2016b or later, consider creating a timetable to store your channel data, using synchronize to merge each new channel into the timetable that will store all your data. If one channel has data at a time another does not, you can have synchronize fill the second channel's entry for that time with missing (for floating-point data, NaN.)

Community Treasure Hunt

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

Start Hunting!