how we can store value in array using loop?
1 回表示 (過去 30 日間)
古いコメントを表示
user(1).will = 0.5;
user(1).rep = 1;
user(1).bid = [3,5,7];
user(1).inter_time=4;
user(2).will = 0.9;
user(2).rep = 0.6;
user(2).bid = [6,5,7];
user(2).inter_time=7;
% Structure of Array of user set
task(1).bud = 8;
task(1).qua = 1;
task(2).bud = 9;
task(2).qua = 2;
task(3).bud = 7;
task(3).qua = 1;
%a = zeros(1,3*2);
%b=zeros(1,3*2);
%c=zeros(1,3*2);
for i=1:2
for j=1:3
%fprintf('i=%d j=%d\n',i,j);
if(not (user(i).bid(j)<=task(j).bud))
continue;
end
com_data_quality = (user(i).will*user(i).rep/user(i).bid(j)*user(i).inter_time);
%a((i-1)*3+j)= com_data_quality;
%b((i-1)*3+j)=i;
%c((i-1)*3+j)=j;
%c = sort(s,'descend');
fprintf('value is %f task is=%d user is=%d \n', com_data_quality,j,i);
end
end
OUTPUT:
value is 0.666667 task is=1 user is=1
value is 0.400000 task is=2 user is=1
value is 0.285714 task is=3 user is=1
value is 0.630000 task is=1 user is=2
value is 0.756000 task is=2 user is=2
value is 0.540000 task is=3 user is=2
This is ouput of my code but i want store this value in 3*3 matrix in which first row store value second row store corresponding task number and 3rd row store user...how it's possible in matlab?HELP ME
0 件のコメント
採用された回答
Matt J
2019 年 4 月 1 日
編集済み: Matt J
2019 年 4 月 1 日
Values=nan(3,3); %<---ADD
for i=1:2
for j=1:3
if(not (user(i).bid(j)<=task(j).bud))
continue;
end
com_data_quality = (user(i).will*user(i).rep/user(i).bid(j)*user(i).inter_time);
Values(i,j)=com_data_quality; %<--ADD
fprintf('value is %f task is=%d user is=%d \n', com_data_quality,j,i);
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!