How do I put it in?

1 Ansicht (letzte 30 Tage)
민제 강
민제 강 am 1 Jun. 2021
Kommentiert: DGM am 2 Jun. 2021
x1 = [-4.2 -2.6 -1 0.6 2.2 3.8 5.4 7 8.6]
x2 = [0.8 2.4 4 5.6 7.2 8.8 10.4 12 13.6]
predictor([x1 x2], dmodel)
[-4.2 0.8], [-4.2 2.4],[-4.2 4],[-4.2 5.6],[-4.2 7.2],[-4.2 8.8],[-4.2 10.4],[-4.2 12],[-4.2 13.6]
[-2.6 0.8],[-2.6 2.4],[-2.6 4],[-2.6 5.6] , ...
I want to put all the x2 values in one x1 value sequentially.
Please let me know! Thank you!

Akzeptierte Antwort

DGM
DGM am 1 Jun. 2021
This isn't quite what you describe, since you're describing a series of 1x2 vectors, but:
x1 = [-4.2 -2.6 -1 0.6 2.2 3.8 5.4 7 8.6];
x2 = [0.8 2.4 4 5.6 7.2 8.8 10.4 12 13.6];
N = numel(x1);
[repelem(x1,N).' repmat(x2.',[N 1])]
ans = 81×2
-4.2000 0.8000 -4.2000 2.4000 -4.2000 4.0000 -4.2000 5.6000 -4.2000 7.2000 -4.2000 8.8000 -4.2000 10.4000 -4.2000 12.0000 -4.2000 13.6000 -2.6000 0.8000
  3 Kommentare
민제 강
민제 강 am 2 Jun. 2021
Thank you!
I have one more question.
How do I apply it to this function in the same way?
function Y = objectivefunction (X)
x1
x2
a = 1;
b = 5.1/(4*pi^2);
c = 5/pi;
r = 6;
s = 10;
t = 1/(8*pi);
Y = a*(x2 - b*x1^2 + c*x1 - r)^2 + s*(1-t)*cos(x1) + s
end
DGM
DGM am 2 Jun. 2021
I have no idea about the requirements of whatever predictor thing you're working with. More generally if you just want to pass two arguments to some function but the calling function only allows you to pass one, you could probably just concatenate the vectors as dimensions allow and then split them afterwards, or you could just stick them in a cell array. I don't see that including every combination is required as in my answer (or SS's).
Maybe someone can chime in with a more specific way to do what you're trying to do for the calling function you're using. I don't do anything with machine learning tools, so maybe suggesting a cell array is a bad idea on my part.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 1 Jun. 2021
It is quite simple.
x1 = [-4.2 -2.6 -1 0.6 2.2 3.8 5.4 7 8.6];
x2 = [0.8 2.4 4 5.6 7.2 8.8 10.4 12 13.6];
x1 = [x1, x2];

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by