Concatenate integer to variable name

조회 수: 15 (최근 30일)
Ioannis Agalliadis
Ioannis Agalliadis 2017년 6월 29일
답변: Steven Lord 2017년 6월 30일
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
Ioannis Agalliadis
Ioannis Agalliadis 2017년 6월 30일
편집: Ioannis Agalliadis 2017년 6월 30일
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 2017년 6월 30일
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...

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 6월 30일
편집: Jan 2017년 6월 30일
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
  댓글 수: 1
Ioannis Agalliadis
Ioannis Agalliadis 2017년 6월 30일
The first applies to my situation! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2017년 6월 30일
"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!

Translated by