Loop that creates Variable from other numbered variable
1 次查看(过去 30 天)
显示 更早的评论
Hello
PROBLEM1
i want to create variable db1,db2 ....db10 where
db1 = corrcoef(A,B1);
i already have B1,B2...B10 created
i tried this
for i=10
db(i) = corrcoef(A,B(i));
end
and i got this msg
"Undefined function or variable 'B'."
Problem 2:
i want to keep doing the process with other variable after
sym1,sym2....sym10
then add all the values to a table
so i'm using this long line
Wavelet = ["haar";"fk4";"fk6";"fk8";"fk14";"fk18";"fk22";"db1";"db2";"db3";"db4";"db5";"db6";"db7";"db8";"db9";"db10";"sym1";"sym2";"sym3";"sym4";"sym5";"sym6";"sym7";"sym8";"sym9";"sym10";"coif1";"coif2";"coif3";"coif4";"coif5";"bior1.1";"bior1.3";"bior1.5";"bior2.2";"bior2.4";"bior2.6";"bior2.8";"bior3.1";"bior3.3";"bior3.5";"bior3.7";"bior3.9";"bior4.4";"bior5.5";"bior6.8";"rbior1.1";"rbior1.3";"rbior1.5";"rbior2.2";"rbior2.4";"rbior2.6";"rbior2.8";"rbior3.1";"rbior3.3";"rbior3.5";"rbior3.7";"rbior3.9";"rbior4.4";"rbior5.5";"rbior6.8";"dmey"];
but i want something shorter and faster to write
5 个评论
Walter Roberson
2023-10-9
Wavelet = ["haar";"fk4";"fk6";"fk8";"fk14";"fk18";"fk22";"db1";"db2";"db3";"db4";"db5";"db6";"db7";"db8";"db9";"db10";"sym1";"sym2";"sym3";"sym4";"sym5";"sym6";"sym7";"sym8";"sym9";"sym10";"coif1";"coif2";"coif3";"coif4";"coif5";"bior1.1";"bior1.3";"bior1.5";"bior2.2";"bior2.4";"bior2.6";"bior2.8";"bior3.1";"bior3.3";"bior3.5";"bior3.7";"bior3.9";"bior4.4";"bior5.5";"bior6.8";"rbior1.1";"rbior1.3";"rbior1.5";"rbior2.2";"rbior2.4";"rbior2.6";"rbior2.8";"rbior3.1";"rbior3.3";"rbior3.5";"rbior3.7";"rbior3.9";"rbior4.4";"rbior5.5";"rbior6.8";"dmey"];
could be written as
Wavelet = ["haar", "fk"+[4 6 8 14 18 22], "db" + (1:10), "sym"+(1:10). "coif" + (1:5), "bior1."+[1 3 5], "bior2."+(2:2:8), "bior3."+(1:2:9) <etc>].';
Stephen23
2023-10-10
"B is actually a signal with a lenght of 2001 "
Your original question shows this error message: "Undefined function or variable 'B'." Which tells us that B actually does not exist in that workspace.
Your question presumes a particular solution, but does not explain what the actual problem is:
采纳的回答
Sulaymon Eshkabilov
2023-10-10
This can be done realtively easy if this is what you want:
A=randi(15, 1, 5); % 1 - by - 5
B1=randi(13, 1,5); % 1 - by - 5
B2=randi(13, 1,5); % 1 - by - 5
B3=randi(13, 1,5); % 1 - by - 5
B4=randi(13, 1,5); % 1 - by - 5
B5=randi(13, 1,5); % 1 - by - 5
...
B = [B1; B2;B3;B4;B5];
N = size(B,1);
db = cell(1,N);
for ii=1:N
db(ii) = {corrcoef(A,B(ii,:))};
DB_final(ii)=db{1,ii}(1,2);
end
celldisp(db)
DB_final % This is how you cna get one final value of the diag elements
0 个评论
更多回答(1 个)
Sulaymon Eshkabilov
2023-10-9
A quick note: in your loop code, there is an err that need to be fixed:
% your code:
% for i=10 computes for i=10 only and skips 1 to 9
% db(i) = corrcoef(A,B(i));
% end
Besides, another point is what is the size of variable B1, B2, ... Bn?
If B1, B2, ... Bn are separate variables (with the same size), you can combine them into one variable (one matrix).
Another point is the size of variable db needs to be noted here, and maybe it can be stored in a cell array from every iteration. E.g.:
% Note that size of A and B compatible to compute correlation coeff's:
A=randi(15, 1, 5); % 1 - by - 5
B1=randi(13, 1,5); % 1 - by - 5
B2=randi(13, 1,5); % 1 - by - 5
B3=randi(13, 1,5); % 1 - by - 5
B4=randi(13, 1,5); % 1 - by - 5
B5=randi(13, 1,5); % 1 - by - 5
...
B = [B1; B2;B3;B4;B5];
N = size(B,1);
db = cell(1,N);
for i=1:N
db(i) = {corrcoef(A,B(i,:))};
end
celldisp(db)
Simularly, you can apply for toher variables as well.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Wavelet Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!