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.
If the data in your file is structured, meaning has tabs or spaces between the numbers you can directly use
importdatato load your data into a matrix. After that, you can useimagescto produce the image. To assign the colors you can change the colormap using thecolormapfunction. So your code would look something like this:Hope that helps!