?
Solved

Can someone please help with this simple Matlab question

Posted on 2009-04-02
1
Medium Priority
?
67 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
yuk99 earned 1000 total points
ID: 24052089
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This video teaches viewers about errors in exception handling.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

777 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