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!