I want to store this line in variable x so then I can plot it is that possible
x= [dataset1, dataset2] = myfunction(sample1); %I know this doesn't work , but I just wanted to give clear example
figure
plot(x(:,1) , x(:,2) , 'b.');

2 件のコメント

Image Analyst
Image Analyst 2016 年 1 月 21 日
What kind of arrays, and how many, do you want your function to return?
lucky_
lucky_ 2016 年 1 月 21 日
sample1 = 1000 and the myfunction is provided by my teacher it long and completed it suppose to generate dataset I know how to plot things but he gave us this line [dataset1, dataset2] = myfunction(sample1) and asked to plot I had an idea that I should run it and then save the data but not sure how to do that

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2016 年 1 月 21 日
編集済み: Star Strider 2016 年 1 月 21 日

0 投票

That depends on how you write your function. If you write it as something like this:
function x = myfunction(sample1)
. . . CALCULATIONS . . .
dataset1 = . . .;
dataset2 = . . .;
x = [dataset1, dataset2];
end
Then ‘x’ would be an (Nx2) matrix that you could then plot as:
figure(1)
plot(x(:,1) , x(:,2) , 'b.')
NOTE I did not actually test this, but it should work.

3 件のコメント

lucky_
lucky_ 2016 年 1 月 21 日
so If have these two each one represent dataset should I store them in variable or in new function I'm still a bit confused :/
[traindata, traintarget] = myfunction(sample1);
[testdata, testtarget] = myfunction(sample2);
Star Strider
Star Strider 2016 年 1 月 21 日
I apparently misunderstood. If you want ‘x’ to be as you defined it, you need to break it up into two separate statements:
[dataset1, dataset2] = myfunction(sample1);
x = [dataset1, dataset2];
then this will work:
figure(1)
plot(x(:,1) , x(:,2) , 'b.');
Star Strider
Star Strider 2016 年 1 月 22 日
The code looks correct. Your ‘myfunction’ could be having problems.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics についてさらに検索

タグ

質問済み:

2016 年 1 月 21 日

コメント済み:

2016 年 1 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by