Could anyone help me how to consider the rows of matrix part by part.
2 ビュー (過去 30 日間)
古いコメントを表示
Code:
B = partitions(2);
G=rand(4,1);
P=rand(4,1);
for d=1:length(B)
for e=1:length(B{d})
for v =1:size(P,2)
for u =1:size(G,1)
Z(u,v) =(300.*log2(1+(((G(u,v)).*(P(u,v))/(0.5+sum(P(1:u-1,v)).*G(u,v))))))
end
end
end
end
In this code, B has two different types of partitions
For first partition {1 2}, I need to take first rows from G and P to calculate Z.
For second partition {1} {2}, I need to take third and fourth row from G and P to calculate Z.
But when I run the code it takes all the rows for G and P for each partition.
Could anyone help me how to take only first two rows for {1 2} and the next two rows for {1} {2}.
0 件のコメント
回答 (1 件)
Shlok
2024 年 9 月 9 日
Hi Jaah,
I understand you're trying to modify your code so that a specific partition only accesses certain rows from G and P. You can achieve this by calculating the starting and ending row indices based on the partition index from the partition structure B. After that, you can loop through only the selected rows. Here's a modified version of your code to accomplish this:
B = partitions(2);
G = rand(4, 1);
P = rand(4, 1);
for d = 1:length(B)
for e = 1:length(B{d})
% Determine the starting and ending indices for G and P based on the partition
startIdx = (d - 1) * 2 + 1;
endIdx = startIdx + 1;
% Calculate Z using the selected rows
for v = 1:size(P, 2)
for u = startIdx:endIdx
Z(u, v) = (300 * log2(1 + (((G(u, v)) .* (P(u, v))) / (0.5 + sum(P(1:u - 1, v)) .* G(u, v)))));
end
end
end
end
disp(Z);
The logic for determining the start and end row indices can be further refined based on your specific requirements.
Hope it helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!