区間に応じて2つの関数を使い分けて演算したい
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
kenichiro inagaki
am 18 Feb. 2021
Kommentiert: kenichiro inagaki
am 19 Feb. 2021
例:
x<0ではy=exp(x), x>=0ではy=sin(x) の yを計算で取り出したいです。
plotのしかたまでは見つけられますが、データをワークスペースにどう取り出せばいいのかわかりません。
0 Kommentare
Akzeptierte Antwort
Hernia Baby
am 18 Feb. 2021
y1 = y(x(x<0));
y2 = y(x(x>=0));
のようにすれば取り出せます。
以下は一度正負で異なる関数を返し、まとめてプロットする方法です。
参考にどうぞ。
clear, clc, close all;
x = -3:0.1:3;
x = x';
y1 = exp(x(x<0));
y2 = sin(x(x>=0));
figure(1);
plot(x,[y1; y2],'o')
3 Kommentare
Hernia Baby
am 19 Feb. 2021
その認識であってます。
列の統合にはカンマ( , )が必要です。
2列目にyを統合する場合は以下の手順を行ってください。
-----------
y = [y1; y2];
xy = [x, y];
-----------
xy(:,1) に x の列ベクトル、xy(:,2) に y の列ベクトル
がそれぞれ格納されます。
Weitere Antworten (0)
Siehe auch
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!