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 9130159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:54:32+00:00 2026-06-17T07:54:32+00:00

I have written a matlab code which would load the matrix written in a

  • 0

I have written a matlab code which would load the matrix written in a text file and then I want to show it as an image. The text file contains integers number from 0 to 2 in a random fashion and I want to represent each in a different colors e.g. 0 in white,1 in some color and 2 in a different color. I would provide the matlab code just below :

clc;
clear all;

for i=1:10
 k=num2str(i);
 f = strcat('test_file_num_',k,'.txt');
 a{i} = fileread(f);

 [m,n] = size(a{i});

 a{i} = reshape(a{i},12,10);
 a{i} = a{i}';
 a{i} = a{i}(:,1:10);

end

There are 10 text file in the folder each of which contain a random matrix containing integer numbers 0 to 2 and name of each text file starts with “test_file_num_” and in a{i} I have the matrix which is 10×10 matrix. Now I want to represent the a{i} matrix as an image or graph or anything but to have something which would show the contents the matrix in a different color. Thanks for all your help.

  • 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-17T07:54:33+00:00Added an answer on June 17, 2026 at 7:54 am

    If the data in your file is structured, meaning has tabs or spaces between the numbers you can directly use importdata to load your data into a matrix. After that, you can use imagesc to produce the image. To assign the colors you can change the colormap using the colormap function. So your code would look something like this:

    % Example data
    A = floor(3*rand(10)); 
    % Change colormap with just 3 colors (Red,Green,Blue)
    cmap = [1 0 0;0 1 0;0 0 1];
    figure; imagesc(A); colormap(cmap); colorbar;
    

    Hope that helps!

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

Sidebar

Related Questions

I have written some piece of code for my program in Matlab 7.10.0 which
I have written a code in matlab which modulate and demodulate some signals. I
I have written some matlab code for image analysis that searches for clusters in
I'm trying to rewrite code I've written in matlab in C++ instead. I have
I have written the following code in MATLAB to process large images of the
I have this line of code in MATLAB, written by someone else: c=a.'/b I
I have a certain code written in Matlab. I wanted to obtain similar results
I have written a code for the bisection algorithm in MatLab. I have based
I have written a code in MATLAB that allows me to generate a random
I have written a code in matlab script. I need to finish it up

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.