Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Code Matlab => Scilab > Matlab-Scilab equivalents > O > ones (Matlab function)

ones (Matlab function)

Create an array of all ones

Matlab/Scilab equivalent

Matlab Scilab
ones
ones(n)
ones(sz1, .., szN)
ones(Sizes)
ones(.., typename)
ones(.., 'like', p)

% No equivalent
ones()
ones(n, n)
ones(sz1, .., szN)
repmat(1, Sizes)
ones(.., typename)
// No equivalent

ones(A)  // only size(A) is considered

Particular cases

Note that in Matlab, A can contain complex values (in these cases, only real part of A is taken in account), what Scilab function do not tolerate.

// Scilab version
B=ones(A)

Most differences stem from the use of ones in conjunction with size. In Scilab you do not need to use size:

% Matlab version
A = [1 2 ; 3 4];
B = ones(size(A))
B  = [ 1. 1. ; 1. 1.]
// Scilab version
A = [1 2 ; 3 4];
B = ones(A)
B  =[ 1 1 ; 1 1]

As a result, if A is a scalar, then Matlab will return a A*A matrix of ones but in Scilab you get a 1 (just because a scalar is a 1*1 matrix), so use ones(A,A) to get the same matrix B. If A is a vector, Scilab and Matlab give the same B. Finally, if A is a matrix, in Scilab, B will be a matrix having the same size as A whereas in Matlab, you get an error message.

Examples

Matlab Scilab
B = ones(2)
B = [1,1;1,1]
B = ones(2,2)
B = [1,1;1,1]
B = ones([3,3])
B = [1,1,1;1,1,1;1,1,1]
B = ones(2)
B = 1
B = ones(2,2)
B = [1,1;1,1]
B = ones([3,3])
B = [1,1]
Report an issue
<< O O otherwise (Matlab function) >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:35:42 CET 2022