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

  • SEARCH
  • Home
  • 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 6903175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:53:34+00:00 2026-05-27T07:53:34+00:00

I’ve got some code, and I’ve been trying to make some minor tweaks to

  • 0

I’ve got some code, and I’ve been trying to make some minor tweaks to it. It used to use fgets to load in a single character from a line, and use it to colour points in a 3D plot. So it would read

a
p
p
n
c

and then use other data files to assign what x, y, z points to give these. The result is a really pretty 3D plot.

I’ve edited the input file so it reads

0
1
1
0
2
2
0

and I want it to colour numbers the same colour.

This is where I’ve gotten so far with the code:

    function PlotCluster(mcStep)

   clear all

   filename = input('Please enter filename:   ', 's');

   disp('Loading hopping site coordinates ...')
   load x.dat
   load y.dat
   load z.dat
   temp = z;
   z = x;
   x = temp;
   n_sites = length(x);

       disp('Loading hopping site types ...')
   fp = fopen([filename]);
   data = load(filename);  %# Load the data

   % Plot the devices
   % ----------------

   disp('Plotting the sample surface ...')
   figure
   disp('Hello world!')

   ia = data == 0;
   in = data == 1;
   ip = data == 2;
   disp('Hello Again')

   plot3(x(ia),y(ia),z(ia),'b.') %,'MarkerSize',4)
   hold on
   plot3(x(ic),y(ic),z(ic),'b.') %,'MarkerSize',4)
   plot3(x(in),y(in),z(in),'g.') %,'MarkerSize',4)
   plot3(x(ip),y(ip),z(ip),'r.') %,'MarkerSize',4)
   daspect([1 1 1])
   set(gca,'Projection','Perspective')
   set(gca,'FontSize',16)   
   axis tight
   xlabel('z (nm)','FontSize',18)
   ylabel('y (nm)','FontSize',18)
   zlabel('x (nm)','FontSize',18)
   %title(['Metropolis Monte Carlo step ' num2str(mcStep)])

   view([126.5   23])

My issue is I’m getting this error

Index exceeds matrix dimensions.

Error in PlotCluster (line 34)
   plot3(x(ia),y(ia),z(ia),'b.') %,'MarkerSize',4)

And I don’t see why ia would go out of bounds of the x array. Is it to do with changing the fgets to a load statement? It was the only way to get it read the correct numbers in (not 49s and 50s which was very odd.)

The main bits that are sticking me are these lines (where the number used to correspond to ‘a’,’n’,’p’ etc)

   ia = data == 0;
   in = data == 1;
   ip = data == 2;

They look like implied if statements with assignment from data to ia etc. where ia becomes an array. But I’m not sure.

Any help understanding this would be greatly appreciated.

  • 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-05-27T07:53:35+00:00Added an answer on May 27, 2026 at 7:53 am

    I’ve fixed the issue, I hadn’t updated my input correctly. To clear this up for anyone who comes to this question: ia = data ==0 means ‘Make an array the same size as data, and fill it with 1 or 0 depending on if the logic (data == 0) is true or false’

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

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace

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.