Solved

Can someone please help with this simple Matlab question

Posted on 2009-04-02
1
57 Views
Last Modified: 2016-02-10
Question is;

Create a (10 by 10) matrix initialized to all zeros.
Input the numbers 1 to 100 using 2 nested for loops.

my attempt is in the codebox below

Can someone please advise?
Z=zeros(10,10);

count=0;

for x = 1:10

    for y = 1:10

        Z(x,y)=count+1;

    end

end

        Z

Open in new window

0
Comment
Question by:jtiernan2008
1 Comment
 
LVL 15

Accepted Solution

by:
yuk99 earned 250 total points
Comment Utility
This will be very slow in Matlab.
Do this:
Z=reshape(1:100,10,10)';

1:100 creates vector and RESHAPE function reshapes it to square matrix. You have to transpose it with ' to have sequence by rows.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now