Hi there,
I have a Matlab script like this :
b2=area([array1+array2-array3+array4],'EdgeColor','none','FaceAlpha',0.3); %array1,2,3,4 are equal size arrays
In this way, the sum inside brackets has the same color and I would like each array of this sum to have different color. How can I specify it to have 4 different colors, 1 for each array?
Thank you for your time.

 채택된 답변

Star Strider
Star Strider 2022년 11월 12일

0 개 추천

With so little information, I can only suggest one approach, that being serial area calls or concatenating the ‘array’ variables.
Perhaps —
% x = 1:10;
array1 = rand(1,10);
array2 = rand(1,10);
array3 = rand(1,10);
array4 = rand(1,10);
figure
b2=area([array1+array2-array3+array4],'EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Original')
figure
b2=area([array1; array2-array3; array4].','EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Separated & Concatenated 1')
figure
b2=area([array1; array2; -array3; array4].','EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Separated & Concatenated 2')
This operation:
array2-array3
may prevent the vectors in that term from being separated into two different arrays. I present two different way s of dealing with it here
.

댓글 수: 5

panagiotis skrempos
panagiotis skrempos 2022년 11월 13일
Thank you for your quick response, in order to elaborate more on the topic: I have 4 arrays,1x24 each, and I need to present them as stacked.All arrays have positive elements, however 2 of them contribute in a postivie way and the other 2 in a negative way to the energy levels that I am studying as part of my thesis. I have the 2 positive arrays lets say array1, array2 and I want to have array1 starting from x-axis and then at the upper points (elementwise) of array1, array2 to start. For the negative arrays, lets call them array3 and array4 I want quite the opposite, meaning that array3 starts from x-axis and goes to the negative direction and at then to its lower point array4 to add(stack). How I can do this?
panagiotis skrempos
panagiotis skrempos 2022년 11월 13일
Something like this lets say...
Star Strider
Star Strider 2022년 11월 13일
편집: Star Strider 2022년 11월 14일
I do not completely understand wihat you want to do, or how (or if) you want to combine them. It may be necessary to separately use the area function to create the positive vector plots, then use hold to add the negative vector plots.
EDIT — (14 Nov 2022 at 3:26)
I just now saw the example.
See if this does what you want —
pos = rand(24,2);
neg = -rand(24,2);
x = 1:24;
% figure
% a1 = area(x,pos, "DisplayName","Positive");
% hold on
% a2 = area(x,neg, "DisplayName","Negative");
% hold off
% grid
% legend( 'Location','best')
figure
a1 = area(x,pos);
hold on
a2 = area(x,neg);
hold off
grid
legend("Positive 1","Positive 2","Negative 1","Negative 2", "Location","best")
I added the legend simply to be certain it could be done correctly if you want a legend.
Using 'DisplayName' (with either single or double quotes) does not work as I would like it to. I left that code in, however commented-out.
.
panagiotis skrempos
panagiotis skrempos 2022년 11월 14일
Perfect...That exactly what i needed, thank you so much for your help and your time. I am really grateful
Star Strider
Star Strider 2022년 11월 14일
As always, my pleasure!
This was an interesting problem!
.

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

추가 답변 (1개)

KSSV
KSSV 2022년 11월 12일

0 개 추천

figure
hold on
area(array1,'EdgeColor','none','FaceColor','r');
area(array2,'EdgeColor','none','FaceColor','b');
area(array3,'EdgeColor','none','FaceColor','g');
area(array4,'EdgeColor','none','FaceColor','m');
See to it that, the areas are in the decreasing order.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2022년 11월 12일

댓글:

2022년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by