Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:01:02+00:00 2026-06-17T08:01:02+00:00

I am only a novice programmer, and I would like some help with this

  • 0

I am only a novice programmer, and I would like some help with this problem.

I am currently running simulations of particles that interact and move around on a two-dimensional lattice. The data of where the particles are at any point is stored in a two-dimensional array that I use during the simulation itself.After the simulation, I want to be able to visually see where all of the particles end up. Currently, I send the data to MATLAB, and have it literally plot each particle on a figure. This works, and creates “pictures” of my system configuration. However, for large numbers of particles in a large lattice (With dimensions like 600 particles wide by 1200 particles tall), this makes prohibitively slow-processing pictures, that MATLAB and word processing are very slow to deal with, and which uses up a lot of memory and space.

There must be a better way to do this, does anyone have any ideas on better ways to view my system or control the data?

My matlab code works as the following:

%--------------------------------------- Particle Picture
clc; clear all;
particle_file = fopen('ABC_Particles_600X1200T1.txt');
particles = fscanf(particle_file,'%f');
fclose(particle_file);

figure(3);
hold on;
sizex = 600;
sizey = 1200;

for a = 1:1:sizey*sizex
    b = int32(a);
    if particles(a) == 0
        plot(mod(b,sizex)+1,idivide(b,sizex)+1,'c')
    end
    if particles(a) == 1
        plot(mod(b,sizex)+1,idivide(b,sizex)+1,'r')
    end
    if particles(a) == 2
        plot(mod(b,sizex)+1,idivide(b,sizex)+1,'k')
    end
end    
title('Size 600X1200; Time T = 1')
axis([0 sizex 0 sizey])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:01:03+00:00Added an answer on June 17, 2026 at 8:01 am

    you can vectorize your code using logical conditions instead of the loop. for example, z=(particles==0) is a vector of 0 and 1‘s, where you get the value 1 where the element of particles=0. This replaces the code:

    for a=1:n
         if particles(a) == 0
            z(a)=1
        else
            z(a)=0
        end
    end
    

    So, first we reshape particles from a long vector to a matrix:

    p=reshape(particles,600,1200);
    

    then we can use logical conditions as before, or similarly, the function find to get the x and y coordinates of the p according to what you wrote

    [x0 y0]=find(p==0);
    [x1 y1]=find(p==1);
    [x2 y2]=find(p==2);
    

    Then we can just plot it:

    plot(x0,y0,'c',x1,y1,'r',x2,y2,'k')
    

    by the way, if 0,1,2 are the only values your data have you can skip all this and just use:

    imagesc(p)
    

    That will color code your points differently, but you can change the colormap to whatever you want

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This only happens in some IE's. Here: http://animactions.ca/Animactions/volet_entreprise.php You may notice that when you
I'm a novice php programmer and having a problem assembling this code to work.
I'm a novice programmer. This may be a simple problem but I've never seen
I'll admit I'm a novice programmer and really the only experience I have is
I'm a novice Android programmer, and to help me understand how Intents really work,
I'm a rather novice programmer who recently came up with a solution that works
(I'm a complete novice programmer) I recently came across a problem with my custom
Forgive me if this is a silly question but I am a novice programmer,
Can somebody help a novice programmer to understand if his solution is correct? My
Novice Programmer here - I have an application with two threads that I start,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.