現在この質問をフォロー中です
- アクティビティ フィードにアップデートが表示されます。
- 通知基本設定に応じて電子メールを受け取ることができます。
Hello Everyone, I am new in MATLAB and I want to get result of this code(MATLAB2021a), its run correctly but doesn't show the result. Anyone can help me?? thanks in advance
2 ビュー (過去 30 日間)
表示 古いコメント
c=[ ];
global d;
c(1,d)= ran(10,21);
function x = ran(min,max)
x= fix ((max-min).*rand(1,1) + min)+1;
end
It should give me number but doesn't show any numbers.
Many Thanks for your help
4 件のコメント
ARAM KHURSHEED
2022 年 1 月 11 日
@KALYAN ACHARJYA Thank you so much, its work like you wrote,but i need it to give me result as c(1,d)=ran(10,21); becuase its a part of my program. could you tell me why NewNetwork doesn't get the result??

Cris LaPierre
2022 年 1 月 11 日
OP's comments moved here.
i want to get this table

the attachment code is to create this table, the result should be save in NewNetwok but this not occure this is my problem .
Best Regards
%RATs%%%%%%%%%%%
global UMTS;
global LTE;
global WIFI;
global WIMAX;
global FiveG;
global CostperByte;
global Security;
global DataRate;
global PacketDelay;
global PacketJitter;
global PacketLoss;
%%%%%%%%%%%%%%%%
NetworksNames=[];
NetworksList=["LTE";"WIMAX";"UMTS";"WIFI";"FiveG"];
N= size (NetworksList);
N=N(2);
UMTSToString=1;
LTEToString=1;
WIFIToString=1;
WIMAXToString=1;
FiveGToString=1;
for i=1:N
NewNetwork=[];
switch NetworksList(i)
case 'WIFI'
% %{
NewNetwork(1,CostperByte)=5 ;
if mod(WIFIToString,2) == 1
NewNetwork(1,CostperByte)=10 ;
end
NewNetwork(1,Security)= 50;
NewNetwork(1,DataRate)= ran(1,11);
NewNetwork(1,PacketDelay)= ran(100,150);
NewNetwork(1,PacketJitter)= ran(10,20);
NewNetwork(1,PacketLoss)= ran(20,80);
NetworksNames=[NetworksNames,"Wi-Fi"+" "+int2str(WIFIToString)];
WIFIToString=WIFIToString+1;
% %}
%{
NewNetwork(1,CostperByte)=ran(0,1) ;
NewNetwork(1,Security)= ran(0,90) ;
NewNetwork(1,DataRate)= ran(0.1,5);
NewNetwork(1,PacketDelay)= ran(50,200);
NewNetwork(1,PacketJitter)= ran(0,8);
NewNetwork(1,PacketLoss)= ran(0,4);
NetworksNames=[NetworksNames,"Wi-Fi"+" "+int2str(WIFIToString)];
WIFIToString=WIFIToString+1;
%}
case 'UMTS'
NewNetwork(1,CostperByte)=60;
NewNetwork(1,Security)= 70 ;
if mod(UMTSToString,2) == 1
NewNetwork(1,CostperByte)=80 ;
NewNetwork(1,Security)= 90 ;
end
NewNetwork(1,DataRate)= (2-0.1).*rand(1,1) + 0.1;
NewNetwork(1,PacketDelay)= ran(25,50);
NewNetwork(1,PacketJitter)= ran(5,10);
NewNetwork(1,PacketLoss)= ran(20,80);
NetworksNames=[NetworksNames,"UMTS"+" "+int2str(UMTSToString)];
UMTSToString=UMTSToString+1;
%{
NewNetwork(1,CostperByte)=ran(20,40) ;
NewNetwork(1,Security)= ran(0,90) ;
NewNetwork(1,DataRate)= ran(0.5,2);
NewNetwork(1,PacketDelay)= ran(50,100);
NewNetwork(1,PacketJitter)= ran(0.3,8);
NewNetwork(1,PacketLoss)= ran(0,2);
NetworksNames=[NetworksNames,"UMTS"+" "+int2str(UMTSToString)];
UMTSToString=UMTSToString+1;
%}
case 'LTE'
NewNetwork(1,CostperByte)= 40;
if mod(WIMAXToString,2) == 1
NewNetwork(1,CostperByte)=50 ;
end
NewNetwork(1,Security)= 60;
NewNetwork(1,DataRate)= ran(2,100);
NewNetwork(1,PacketDelay)= ran(50,300);
NewNetwork(1,PacketJitter)= ran(3,12);
NewNetwork(1,PacketLoss)= ran(20,80);
NetworksNames=[NetworksNames,"LTE"+" "+int2str(LTEToString)];
LTEToString=LTEToString+1;
%{
NetworksNames=[NetworksNames,"LTE"+" "+int2str(LTEToString)];
LTEToString=LTEToString+1;
NewNetwork(1,CostperByte)=ran(2,8) ;
NewNetwork(1,Security)= ran(0,90) ;
NewNetwork(1,DataRate)= ran(5,50);
NewNetwork(1,PacketDelay)= ran(50,100);
NewNetwork(1,PacketJitter)= ran(0,5);
NewNetwork(1,PacketLoss)= ran(0,2);
%}
case 'FiveG'
NewNetwork(1,CostperByte)= 100;
if mod(WIMAXToString,2) == 1
NewNetwork(1,CostperByte)=120 ;
end
NewNetwork(1,Security)= ran(80,90);
NewNetwork(1,DataRate)= ran(100,120);
NewNetwork(1,PacketDelay)= ran(0.1,2);
NewNetwork(1,PacketJitter)= ran(0.1,12);
NewNetwork(1,PacketLoss)= ran(1,10);
NetworksNames=[NetworksNames,"5G"+" "+int2str(LTEToString)];
LTEToString=LTEToString+1;
otherwise
NewNetwork(1,CostperByte)= 40;
if mod(WIMAXToString,2) == 1
NewNetwork(1,CostperByte)=50 ;
end
NewNetwork(1,Security)= 60;
NewNetwork(1,DataRate)= ran(1,60);
NewNetwork(1,PacketDelay)= ran(60,100);
NewNetwork(1,PacketJitter)= ran(3,10);
NewNetwork(1,PacketLoss)= ran(20,80);
NetworksNames=[NetworksNames,"WiMax"+" "+int2str(WIMAXToString)];
WIMAXToString=WIMAXToString+1;
%{
NetworksNames=[NetworksNames,"WiMax"+" "+int2str(WIMAXToString)];
WIMAXToString=WIMAXToString+1;
NewNetwork(1,CostperByte)=ran(2,5) ;
NewNetwork(1,Security)= ran(0,90) ;
NewNetwork(1,DataRate)= ran(1,60);
NewNetwork(1,PacketDelay)= ran(50,120);
NewNetwork(1,PacketJitter)= ran(0,5);
NewNetwork(1,PacketLoss)= ran(20,80);
%}
end
end
function T = ran(min,max)
T= fix ((max-min).*rand(1,1) + min)+1;
end
採用された回答
Cris LaPierre
2022 年 1 月 12 日
Here is perhaps some starter code for you on how to create a MATLAB table.
rowNms = ["WIFI";"WIMAX";"UMTS";"LTE"];
varNms = ["CostperByte","Security","DataRate","PacketDelay","PacketJitter","PacketLoss"];
newNetwork = array2table(zeros(4,6), 'VariableNames', varNms);
newNetwork.Properties.RowNames = rowNms;
for r=1:height(newNetwork)
for c = 1:width(newNetwork)
newNetwork{r,c}=ran(randi(100,1),randi(100,1));
end
end
newNetwork
newNetwork = 4×6 table
CostperByte Security DataRate PacketDelay PacketJitter PacketLoss
___________ ________ ________ ___________ ____________ __________
WIFI 21 47 46 70 61 39
WIMAX 17 57 52 58 80 55
UMTS 65 57 36 51 62 29
LTE 30 29 32 72 19 71
function x = ran(min,max)
x= fix ((max-min).*rand(1,1) + min)+1;
end
16 件のコメント
ARAM KHURSHEED
2022 年 1 月 12 日
sorry for annoying, but could give me some more explain about the code, because each Network("WIFI";"WIMAX";"UMTS";"LTE") has different random range of Attribute("CostperByte","Security","DataRate","PacketDelay","PacketJitter","PacketLoss") so, how can i do that?
Could you applay your code on for example on the one network?
Best Regards
Cris LaPierre
2022 年 1 月 12 日
Why don't you make an attempt, and then I can answer specific questions you have about doing it.
ARAM KHURSHEED
2022 年 1 月 12 日
I am doing but i can not get result.
for example, i would like to genereat values (CostperByte","Security","DataRate","PacketDelay","PacketJitter","PacketLoss) for network WIFI
assume this code
switch NetworksList(i)
case 'WIFI'
NewNetwork(1,CostperByte)=5 ;
if mod(WIFIToString,2) == 1
NewNetwork(1,CostperByte)=10 ;
end
NewNetwork(1,Security)= 50;
NewNetwork(1,DataRate)= ran(1,11);
NewNetwork(1,PacketDelay)= ran(100,150);
NewNetwork(1,PacketJitter)= ran(10,20);
NewNetwork(1,PacketLoss)= ran(20,80);
WIFIToString=WIFIToString+1;
i tried to applay your code on the above code but i coudn't to do that i have wrote mentioned code after the two for loop but doesn't give me resault, like:
global UMTS;
global LTE;
global WIFI;
global WIMAX;
global FiveG;
global CostperByte;
global Security;
global DataRate;
global PacketDelay;
global PacketJitter;
global PacketLoss;
WIFIToString=1;
UMTSToString=1;
rowNms = ["WIFI";"WIMAX";"UMTS";"LTE"];
newNetwork.Properties.RowNames = rowNms;
for r=1:height(newNetwork)
for c = 1:width(newNetwork)
switch rowNms(r)
case 'WIFI'
newNetwork(r,c)=10 ;
newNetwork(r,c)= 50;
newNetwork(r,c)= ran(1,11);
newNetwork(r,c)= ran(100,150);
newNetwork(r,c)= ran(10,20);
newNetwork(r,c)= ran(20,80);
WIFIToString=WIFIToString+1;
this dosen't work
Best Regards
Cris LaPierre
2022 年 1 月 12 日
Why are you declaring globals? Is there another script that calls this one?
ARAM KHURSHEED
2022 年 1 月 12 日
No, for now there is no more script, it my mistake i entegrated your code with my code, i removed the global but still no result.
Best Regards
Cris LaPierre
2022 年 1 月 12 日
Here's an example of how I would create the first row. Since you have to code every cell already, I don't find any value in encasing everying in a switch statement.
Be careful with variable names. As you learned in MATLAB Onramp, captialization matters. NewNetwork is not the same variable as newNetwork.
rowNms = ["WIFI";"WIMAX";"UMTS";"LTE"];
varNms = ["CostperByte","Security","DataRate","PacketDelay","PacketJitter","PacketLoss"];
newNetwork = array2table(zeros(4,6), 'VariableNames', varNms);
newNetwork.Properties.RowNames = rowNms;
% WIFI
newNetwork{'WIFI','CostperByte'}=5;
newNetwork{'WIFI','Security'}= 50;
newNetwork{'WIFI','DataRate'}= ran(1,11);
newNetwork{'WIFI','PacketDelay'}= ran(100,150);
newNetwork{'WIFI','PacketJitter'}= ran(10,20);
newNetwork{'WIFI','PacketLoss'}= ran(20,80);
newNetwork
newNetwork = 4×6 table
CostperByte Security DataRate PacketDelay PacketJitter PacketLoss
___________ ________ ________ ___________ ____________ __________
WIFI 5 50 4 108 15 67
WIMAX 0 0 0 0 0 0
UMTS 0 0 0 0 0 0
LTE 0 0 0 0 0 0
function x = ran(min,max)
x= fix ((max-min).*rand(1,1) + min)+1;
end
ARAM KHURSHEED
2022 年 1 月 13 日
So, you removed the for loops and switch statement.
Exactly, There is no values when encasing in switch statement, i have tried this idea but i wanted to get the result by switch statement and using for loops, maybe this needs more effort and experince and i am new in this field thats why i couldn't.
my reason to use switch and loop because i want do that for example for 50 times(50 tables) with keeping the values for all of them.
in your opinion i have export the values as .xls(excel file) file to keep the older values or there is another ways?
about captialization matters, Yes you are right, its called sensetive case i know that i corrected it later.
@Cris LaPierre Thank you so much, please accept my apologies, I bothered you and I am grateful to you
Keep shining
Best Regards
Cris LaPierre
2022 年 1 月 13 日
You will need to find some solution for saving the result of each loop, otherwise each loop will overwrite the result of the previous loop, so at the end you will just have one table - the result of the last loop. If you need the table in MATLAB, perhaps consider using a structure.
ARAM KHURSHEED
2022 年 1 月 13 日
How can i convert the table to Matrix because i want to deal with the values of this table?
I have script which deal with the values of the table.
i have tried these but not useful
newNetwork = table(magic(6));
and also
newNetwork={ : :}
Cris LaPierre
2022 年 1 月 13 日
I don't understand what you are trying to do with the code you shared. They appear to be unrelated to what you are asking to do.
You don't need to convert it to a table. It is all about how you access the data. See this page:
ARAM KHURSHEED
2022 年 1 月 13 日
Thank you so much
i have got it,
i have used the code below and its work
a=table2array(newNetwork);
Best Regards
ARAM KHURSHEED
2022 年 1 月 13 日
Exactly, I have to do that, I have no choice, I want to deal withe values inside the table, I will need only the network names (row names) in the end and at that time I have to think about that.
I am doing network ranking.
So, in the last i will need name of network but whole program is not ready, i am doing it partly(script by script).
Best Regards,
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)