- specify the colors manually in your plot command
- specify the colororder to align with your plotting order
Plot the same color for all iterations of a loop
20 ビュー (過去 30 日間)
古いコメントを表示
I am importing *.mat files from a specified folder (I'm leaving that code out because it works fine). I then import the data into a 1x4 cell (dataT) and pull the file names out to use in my plot legend in the code below:
filePattern = fullfile(myFolder, '*.mat');
theFiles = dir(filePattern);
nFiles = numel(theFiles);
Out = cell(nFiles, 1);
dataT = cell(1, nFiles);
for k = 1:nFiles
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
[~, name] = fileparts(fullFileName);
dataT{k} = load(fullFileName);
Out{k} = name;
end
O=1;
runs=dataT{1,O}.runs;
Legend=cell(length(Out),1);
for p=1:length(Out)
Legend{p}=(Out(p,1));
end
Legend=string(Legend);
Then I process the data and plot 6 graphs. My objective is to plot the data from file 1 as one line on each graph and file 2 as another etc. with each plot, I want the color for the file to stay the same so it makes sense with my legend. This works well for my first 3 plots where I am calling x and y from dataT for a specified range of x. The next set of plots I need to do the same thing but for 20 iterations of the data and plot all 20 lines on each the graph. I am using a for loop to do this and the output has a different color for each iteration of the loop. I need all 20 iterations to be the same color AND to match the color of the file from the first set of plots. My plot command is inside a loop so calling out a color changes all 4 files to the same color.
The top is and example of the first set of plots. Let's say file 1 is red in the top plot, I need all 20 lines belonging to file 1 to be red in the bottom plot as well. Is there a way to do this? Thanks
0 件のコメント
回答 (1 件)
Cris LaPierre
2022 年 9 月 30 日
I don't see any code for actually creating the plots, so it's hard to understand exactly what you are doing.
If you do not specify color, then MATLAB changes the color for each line plotted based on the colors in colororder. By default, there are 7 colors. That means if you plot 8 lines, the first and 8th lines will have the same color.
Your options, then, are to
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!