0

I have some log files and in these log files there are some timestamps from different smartphones. I plotted each log file into different figures. Lets say there are 3 smartphones and each has a specific number like 10, 11, 12 and each smartphone's result keeps in one log file.

Basically what I want to do is, showing the results of these three log files into one figure by using different colors for each log file. Is there anyone who knows how to do it?

EDIT

n=size(allTimeStamps{1},2);
figure(1);
hold on;
for i=1:n
  plot(allTimeStamps{1}{i},mod(allTimeStamps{1}{i},0.3),'Color',colorspec{indexOfFile});
end
title(logFileName);
Nehil Danış
  • 69
  • 1
  • 8
  • 1
    `plot(x, 'r')` where `'r'` stands for the colour (b,k,g,y... are other colours available), and `hold on` (for plotting on the same axes) will do it I think – marsei Jun 28 '17 at 13:36
  • 1
    Thanks. I kinda did the same, now I changed the colors in the way that you said and everything is clear and more visible. I think i didn't work at first, because I was only using [0.3 0.3 0.3], [0.4 0.4 0.4], and so on as colors. That is why all I got was lots of gray lines in one graph. But now everything is okay :) – Nehil Danış Jun 28 '17 at 13:47

1 Answers1

1

You can use the function lines to get the default colors of Matlab in order. This function creates a matrix of n-by-3 that each row within is a new color. However this is good up to 7 colors, otherwise, you can choose another colormap, or use this suggestion.

Here is an example:

data = reshape(1:99,[],3); % some arbitrary data
n = size(data,2);
figure;
hold on;
col = lines(n);
for k = 1:n
  plot(data(:,k),'Color',col(k,:));
end
hold off

enter image description here

(This code is only for demonstrating, in this specific case you don't even need a loop, because plot(data) will give the same result)

EBH
  • 10,350
  • 3
  • 34
  • 59