define the local variable in Function to global
显示 更早的评论
function data= ReadGrasshopperFile( ~, ~,~)
x = randi(10, 1);
y = randi(10, 1);
z = randi(10, 1);
parameters = [x, y, z];
fileName1='M2GHfileName.csv';
fileName2='GH2Matlab.csv';
writematrix(parameters, fileName1);
data = readmatrix(fileName2);
end
This function that I defined it works good.
But, I wanted the x and y and z changed each time that I recall function.
what should I do?
10 个评论
Walter Roberson
2022-2-19
At the moment you are writing one file but reading a different file.
You could create random data, or you could use random numbers to modify the file you read, or if you have several files to read from you could read one at random.
bahar vojdani
2022-2-19
Walter Roberson
2022-2-19
At the end of the function before the end statement add
data = data + randi(10, size(data)) ;
bahar vojdani
2022-2-19
Jan
2022-2-19
"I wanted when I run file it gives me a new number and results." - but this does happen already: randi replies random integers. As long as you do not reset the random number generator manually before, you get new values.
bahar vojdani
2022-2-20
bahar vojdani
2022-2-20
Torsten
2022-2-20
I don't understand what you are trying to do, but I repeat:
The optimization toolbox cannot cope with random inputs that change with iteration.
So you can create random input, but it must remain constant during the optimization process.
bahar vojdani
2022-2-20
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!