필터 지우기
필터 지우기

applying multiple colormaps on one barchart using a for loop

조회 수: 2 (최근 30일)
Glowworm8
Glowworm8 2018년 6월 21일
댓글: Walter Roberson 2018년 6월 25일
I have one set of data in a barchart which I wish to assign 4 different colormaps to if possible. in the matrix, I have R1 (blue), R2-11 (bone), R12 (red), R13-22 (copper) but im unsure how to assign these colours and was hoping to use a for loop with if statements to do it.

채택된 답변

KARSH THARYANI
KARSH THARYANI 2018년 6월 21일
편집: KARSH THARYANI 2018년 6월 21일
You can use the CData property of a bar graph and then add a color to it. See here
Possibly it could be something like this without using a for-loop:
b = rand(10, 1);
graph = bar(b);
graph.FaceColor = 'flat';
graph.CData(1:5, :) = repmat([0 1 0], 5, 1);
graph.CData(6:10, :) = repmat([1 0 0], 5, 1);
  댓글 수: 2
Glowworm8
Glowworm8 2018년 6월 25일
편집: Glowworm8 2018년 6월 25일
sorry for the late reply, thank you for you answer, ive added in my own values and variables but it has come back with this error:
Error in combined (line 141) graph.CData(2:11, :) = repmat([0 1 0], 5, 1 );
Walter Roberson
Walter Roberson 2018년 6월 25일
2:11 is 10 rows, but you are trying to store only 5 rows into it. The 5 in the repmat in the example is the row count.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by