I get this error when using randn "Size inputs must be scalar."

I'm trying to plot the data point and x data coordinate but I'm getting
this error "Size inputs must be scalar."
trainSample = 2000;
testSample = 200000;
[trainData, trainTarget] = myfunction(trainSample);
[testData, tesTarget] = myfunction(testSample);
x=[trainingData, trainingTarget];
y= [testingData, testingTarget];
dataset = randn(trainSamples,2);
dataset2 = randn(trainData,2);
%dataset2 = randn(x,1);
figure
hold on
plot(dataset(:,1) , dataset(:,2) , 'r.');
hold off
hold on
plot(dataset2(:,1) , dataset2(:,2) , 'b.');
hold off
xlabel('x-value');
ylabel('y-value');

2 comentarios

Please show the complete error message, everything in red.
@Walter Roberson
Error using randn Size inputs must be scalar.
Error in draft (line 32) dataset2 = randn(trainData,2);

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de En. de 2016
Editada: Walter Roberson el 22 de En. de 2016
My guess is that you want to replace
dataset2 = randn(trainData,2);
with
dataset2 = randn(testSample,2);
Also notice that trainSamples and trainSample are not the same variable.

5 comentarios

lucky_
lucky_ el 22 de En. de 2016
Editada: Walter Roberson el 22 de En. de 2016
I think this work but why does my plot overlap I can see the plot from this line
plot(dataset2(:,1) , dataset2(:,2) , 'b.');
but I can't see the red plot ?
You are drawing 200000 blue points after you draw 2000 red points that have the same distribution of values. The red points are hidden behind the blue points.
By the way, why are you using randn() and dataset2, when you have your testData and trainData already built? There is no relationship between your testData or trainData and the randn() values that you generate.
Was your expectation that you would be extracting random samples from within testData or trainData? Because that is not what randn() is for.
I just wanted to plot dataset by plotting the data point and x data coordinate so I changed my code a bit however I'm not getting the result that I was aiming for which is a lot of red and blue points from this code I'm getting a lot of red points and 1 or two blue points I'm not sure where I've gone wrong
trainSample = 2000;
testSample = 200000;
%myfunction generate two matrices
[trainData, trainTarget] = myfunction(trainSample);
[testData, tesTarget] = myfunction(testSample);
x=[trainingData, trainingTarget];
y= [testingData, testingTarget];
dataset = randn(trainSamples,2);
%dataset2 = randn(trainData,2);
%dataset2 = randn(x,1);
figure
hold on
plot(dataset(:,1) , dataset(:,2) , 'r.');
hold off
hold on
plot(trainData(:,1) , trainData(:,2) , 'b.');
hold off
xlabel('x-value');
ylabel('y-value');
A variable named "trainSamples" does not exist in your code (only "trainSample").
Best wishes
Torsten.
dataset = trainData(:,1:2);
dateset2 = testData(:,1:2);
plot(dataset(:,1) , dataset(:,2) , 'r.');
hold on
plot(dataset2(:,1) , dataset2(:,2) , 'b.');

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de En. de 2016

Comentada:

el 22 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by