1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function [X,Y]=checkXYPair(typeOfPlot,x,y,current_figure,cur_draw_mode)
ok=%F;
if type(y)==13 // If y is a function
f=y;
if and(size(x)~=1) // then x *must* be a vector
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input argument #%d: A vector expected.\n"),typeOfPlot, 2));
return;
end
t=x(:); // to ensure that t is a column vector
[nArgOut,vectInput]=check2dFun(typeOfPlot,f,t,current_figure,cur_draw_mode);
if nArgOut==1
X=t;
if vectInput
Y=f(t);
else
Y=zeros(length(t),1);
for i=1:length(t)
Y(i)=f(t(i));
end
end
elseif nArgOut==2
if vectInput
[X,Y]=f(t);
else
X=zeros(length(t),1);
Y=zeros(length(t),1);
for i=1:length(t)
// CANNOT DO THE SAME WITH X(i) and Y(i)
// instead of xt and yt (scilab parser sees the stuff
// as a comparison)
[xt,yt]=f(t(i));
X(i)=xt;Y(i)=yt;
end
end
end
else // "classical" case
X=x;
Y=y;
XScal = isscalar(X);
YScal = isscalar(Y);
transposeX = %f;
transposeY = %f;
if size(X,1)==1 & ~XScal, X=X', transposeX = %t; end; // Transpose the row vectors,
if size(Y,1)==1 & ~YScal, Y=Y', transposeY = %t; end; // but no need to transpose scalars.
if transposeX == ~transposeY then
if transposeX == %t then
warning(_("Transposing row vector X to get compatible dimensions"));
else
warning(_("Transposing row vector Y to get compatible dimensions"));
end
end
if (size(X)==[0 0])
ok=%F
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input argument #%d: A non empty matrix expected.\n"),typeOfPlot, 2));
return;
end
if (size(Y)==[0 0])
ok=%F
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input argument #%d: A non empty matrix expected.\n"),typeOfPlot, 3));
return;
end
if and(size(X)==size(Y)) then
// same size for X and Y
ok=%T;
return;
end
if (size(X,2)==1) & (size(Y,1)==size(X,1))
// X is a vector
ok=%T;
return;
end
if (size(X,2)==1) & (size(Y,2)==size(X,1))
// X is a column vector and Y has as many columns as X has rows.
// Y cannot be a square matrix here, because it would have fallen in the previous case (above) and returned.
if ~YScal then
warning(_("Transposing data matrix Y to get compatible dimensions"));
Y=Y';
end
ok=%T;
return;
end
if (size(X,2) == 1) & (size(Y,2) == 1) & (size(Y,1) <> size(X,1)) ...
& (size(Y,1) ~= 1) then
// X and Y are vectors but not of same size
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: Incompatible dimensions.\n"),typeOfPlot, 2, 3));
return;
end
// new case : plot(MAT4x4,[1 2 3 4]) HERE Y is a vector and X a matrix
// Here Y is always a column vector
// extend y to be a 4x4 matrix defined as [1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4]
if or(size(Y) == 1) then
if size(X,1) == size(Y,1) then
y=Y;
elseif size(X,1) == size(Y,2) & ~YScal then
// Y has as many columns as X has rows. Transpose Y to fit X.
warning(_("Transposing data matrix Y to get compatible dimensions"));
y=Y(:);
elseif size(X,2) == size(Y,1) & ~YScal & ~XScal then
// Y has as many rows as X has columns. Transpose X to fit Y.
warning(_("Transposing column vector X to get row vector"));
X=X';
y=Y(:);
elseif size(X,2) == size(Y,2) then
y=Y;
else
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: Incompatible dimensions.\n"),typeOfPlot,2, 3));
return;
end
// concatenante y in columns
Y=y(:,ones(1,size(X,2)));
ok=%T;
return;
end
if ~ok
ResetFigureDDM(current_figure, cur_draw_mode)
error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: Incompatible dimensions.\n"),typeOfPlot, 2, 3));
return;
end
end
// end of checkXYPair
endfunction
|