Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can someone please help with this simple Matlab question

Posted on 2009-04-02
1
Medium Priority
?
69 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

609 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