I am trying to make a matrix that generates random numbers but each column is associated with a different variable. To be specific I need a 60x6 matrix that has columns for; force, pressure, torque, thickness and radius with the last column being the cost function for the genetic algorithm. I also dont know how to define the cost function.
m=zeros(60,6);
F=m(1);
P=m(2);
T=m(3);
r=m(4);
t=m(5);
F=1000+rand(60,1)*99000;
P=100+rand(60,1)*900;
T=10+rand(60,1)*90;
r=.05+rand(60,1)*.04;
t=.0001+rand(60,1)*.0008;

답변 (1개)

Walter Roberson
Walter Roberson 2018년 11월 5일

0 개 추천

There is no way in MATLAB to create a variable that "aliases" a column of a matrix. You will need to construct the variables with rand and then
m = [F P T r t] ;

댓글 수: 4

vincent stevenson
vincent stevenson 2018년 11월 5일
That is exactly what i was missing, thank you. Another thing I'm wondering is how to put my cost function in. ? = ((?−2??^2)/2??^2))^2. Do I just change those into characters that I can use like a,b,c?
Walter Roberson
Walter Roberson 2018년 11월 5일
Odd, I am having difficulty figuring out what character encoding is being used for your string ? = ((?−2??^2)/2??^2))^2
function cost = obj(x)
theta = x(1); sigma = x(2); s = x(3);
cost = pi_(theta, sigma, s);
function result = pi_(theta, sigma, s)
result = (theta./(2*sigma.*s.^2) - 1).^2;
It is not clear what this function of 3 variables has to do with the five variables force, pressure, torque, thickness and radius.
Walter Roberson
Walter Roberson 2018년 11월 6일
Ah, finally found the character encodings for those characters. They are part of the Mathematical Alphanumeric Symbols block that starts from U+1D400

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2018년 11월 5일

댓글:

2018년 11월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by