To find the similar function
Afficher commentaires plus anciens
Is there a function (excluding the below) which can do similar task like:
y = zeros(1500,500);
1 commentaire
DGM
le 26 Fév 2022
Are you asking for a replacement for zeros()?
If you are, that implies that there's a reason why zeros() can't be used. To recommend an alternative, one would have to know what those reasons are.
Réponses (1)
John D'Errico
le 26 Fév 2022
0 votes
Why would there be a different one? Do you really need multiple ways to do this, especially since any other way you would do it would be surely be more inefficient than just using zeros?
So is this a homework assignment, since this is exactly the kind of question we might see in a homework assignment? If so, is there a good reason why you did not tell us that?
I'll give you some hints. You could do it with repmat. You could use ones. You could even use repelem. You could even use toeplitz. Or you could use simple matrix indexing. There are many things you could do. But since this is surely homework, then it is something you need to think about, not be handed the solution.
4 commentaires
Amy Topaz
le 26 Fév 2022
There's a reference list in the documentation:
There's also a basic commands "cheat sheet":
As for using these other methods to create an array of zeros, I doubt there are any explicit examples, as they'd all be generally wasteful to use.
The following are all roundabout ways to create a 5x5 double array of zeros:
A = zeros(5); % the sensible way
A = 0*ones(5); % multiplication by zero
A = 0*rand(5); % multiplication by zero
A = repmat(0,5,5); % replication
A = toeplitz([0 0 0 0 0]); % note that the vector is itself a case in generating a zero-array
A = [0 0 0 0 0] + [0 0 0 0 0].'; % implicit expansion, see above
A = double(false(5)); % recasting
A = round(0.5*rand(5)); % rounding
A = min(rand(5),0); % truncation
A = ones(5)-ones(5); % additive elimination
A = mean('='-'<>')*(';'-':':diff('▃█')).'*('○◔◑◕●'); % now i'm being silly
I'm sure with a little creativity, there really is no limit to how overcomplicated it can be.
Walter Roberson
le 26 Fév 2022
Also,
"You can add one or more elements to a matrix by placing them outside of the existing row and column index boundaries. MATLAB automatically pads the matrix with zeros to keep it rectangular."
"Do you know how do we know about these functions?"
Using the MATLAB help:
- Scroll to the bottom of the ZEROS documentation, you will find links to related functions:

- while you have the ZEROS help open take a look at the browser panel on the left-hand side, then click on the last link before the function title, it will take you to a page with many more functions that create matrices in many different ways:

The MATLAB help is very large: the more you practice browsing it, the easier it will be to find information.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!