How to change color of line within multiple ranges of same line
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lets say I have the following 1xn matrix:
mat =
2
4
8
6
32
64
28
256
512
1024
2048
4096
How can I plot the line to display specific colors along certain ranges (ie. default blue from 1:3, green from 4:7, white/invisible from 8:10, red 11:12)?
The solutions I have found are for x,y plots but I am not sure how apply these display alterations to a matrix/vector (insofar as that is concerned, I do not really understand how Matlab creates x,y plots from one dimensional vectors).
Thanks for any help.
0 Commenti
Risposta accettata
Star Strider
il 6 Dic 2015
This looks a bit strange, but it does what you want:
mat = [ 2
4
8
16
32
64
128
256
512
1024
2048
4096];
x = [1:size(mat,1)];
rmat = reshape(mat, 3, 4);
rx = reshape(x, 3, 4);
c = [0 0 1; 0 1 0; 1 1 1; 1 0 0];
figure(1)
semilogy(rx(:,1), rmat(:,1), 'Color',c(1,:))
hold on
for k1 = 2:size(rmat,2)
plot(rx(:,k1), rmat(:,k1), 'Color',c(k1,:))
end
hold off
grid
I did a semilogy plot so I could verify that it worked.
15 Commenti
Star Strider
il 12 Dic 2015
It’s because the latest code was written to be more general. The early (particularly first) code was written only for that specific example. The latest code is correct, but you have to make the appropriate changes to it (specifically ‘ix_mtx’) to use it with other data.
You have 32 data in your actual data. To use my original code with it, you would have to do a reshape call that divided it into either a (16x2) or (8x4) matrix (or the obvious transposes of those). The data would not divide as you want them to here.
Not all code is robust, or intended to be. Frequently, here on MATLAB Answers, we write code to Answer only a specific Question. If the actual application is significantly different from the ‘example’ Question, as it was here, the original code will quite likely not work in the code's eventually intended application.
The only reasonably robust code you will find contributed by many of the user community is on the File Exchange. It is robust because it was designed to be, and not as a one-off, as most MATLAB Answers code are.
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!