Filter löschen
Filter löschen

how to declare vector of size 64

121 Ansichten (letzte 30 Tage)
Anamika baruah
Anamika baruah am 6 Jun. 2014
Kommentiert: DGM am 27 Aug. 2024 um 19:14
I am trying to declare a vector of size 64 like zeros(64) but it gives all zero values,so i want to know how to declare vector of size 64

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 6 Jun. 2014
There is no declaration of vectors in Matlab, you can pre-allocate memory by creating your array with zeros or whatever you want.

Weitere Antworten (2)

Roger Wohlwend
Roger Wohlwend am 6 Jun. 2014
You cannot just declare a vector of a certain size without giving the elements a certain value.
A = zeros(64,1);
B = ones(64,1);
C = NaN(64,1);
These are three ways to declare a vector mit 64 elements. The first (A) is a vector of zeros, the second (B) a vector of ones and the latter (C) one of NaN.
  1 Kommentar
DGM
DGM am 27 Aug. 2024 um 19:14
In the spirit of variable declaration, it's worth noting that the variable class can be specified during preallocation -- within certain limits. For example
A = zeros(64,1,'double');
B = ones(64,1,'uint8');
The zeros() and ones() functions create 'double' arrays by default, but any numeric class can be used -- 'double','single','uint8','uint16','uint32','uint64','int8','int16','int32','int64'. Since R2016a, 'logical' is also supported.
C = NaN(64,1,'single');
Obviously NaN() only supports float classes 'single' and 'double'.
While true() and false() do not allow explicit class specification, they can also be used to preallocate logical arrays instead of using ones(...,'logical') and zeros(...,'logical')
D = true(64,1);
E = false(64,1);

Melden Sie sich an, um zu kommentieren.


VISHAL BATHRINATH
VISHAL BATHRINATH am 27 Aug. 2024 um 16:45
% create variable that contains vector
x = 1 : 64;
% display the output
disp(x);

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by