I need some assistance on the problem described below. I believe it is more clearer than the earlier post.
%% Problem Description.
% This code represent a 2D spray divided into 5 layers.
% X(SL) represent the axial length,Y(h), the radial length and Z represent the AFR(air-fuel-ratio).
% My intention is to generated a gray color intensity using the Z(AFR) matrix and then distribute
% it into these 5 zones instead of using the FaceColor "y,y,y,y,y" in the code.
% My attempt to use mat2gray,imagesc did not yield any fruit.
% The rsult should be real-time since the variables X,Y and Z are prone to change.
% (The data files for X,Y and Z currently used are attached)
% Color Intensity variation over area stack.
L=5;
for j=1:L % L is the number of layers.
X(j,:)=SL(j,:); % represent the axial length of spray zones
Y(j,:)=h(j,:); % axial length of spray zones
Z(j,:)=AFR(j,:); % Air -fuel Ratio
end
% I = mat2gray(Z,[0 max(max(Z))]);
% imshow(I, []);
Color=['y' 'y' 'y' 'y' 'y'];
figure(14)
hold on
for j=L:-1:1
Ar(j,:)=area(X(j,:)*1000,(Y(j,:)*1000),'FaceColor',Color(j));
Ar(j,:)=area(X(j,:)*1000,(Y(j,:)*1000)*-1,'FaceColor',Color(j));
end
axis([0 350 -100 100]);
grid on
box on
set(gca,'linewidth',1)
xlabel('X [mm]');
ylabel('Y [mm]')

2 Comments

Unfortunately, code that doesn't do what you want doesn't help much in understanding what you want it to do.
If I understood correctly, you want to colour a spray divided into zones according to the AFR. What is the shape of the spray (conical/triangular in 2D)? What is the shape of the zones?
I don't really understand what your SL and h array represent. A drawing of the spray and the zones would help.
Note that:
for j=1:L % L is the number of layers.
X(j,:)=SL(j,:); % represent the axial length of spray zones
Y(j,:)=h(j,:); % axial length of spray zones
Z(j,:)=AFR(j,:); % Air -fuel Ratio
end
is simply:
X = SL; Y = h; Z = AFR;
and really, there's no point in renaming variables, you could simply use SL, h, and AFR wherever you're using X, Y and Z.
Thanks so much Guillaume for your complement. You are absolutely right the way you have understood the question.I actually ought not to have added the above loop since AFR size is one step less in length (i-1). The shape is triangular based on the value of SL and h. See the attached figure(Spray zones). The horizontal axis represent lenght SL, the vertical height represet h. AFR should fill in those small packet like shaped, which I was unable to code(my code only produce plot attached).

Sign in to comment.

 Accepted Answer

Guillaume
Guillaume on 1 Jul 2019
Edited: Guillaume on 1 Jul 2019
Note that AFR should hav one less row as well as column.
Probably, the simplest way to create your spray:
pdata = surf2patch(SL, h, zeros(size(h), AFR(1:end-1, :)));
figure;
patch(pdata, 'FaceColor', 'flat', 'EdgeColor', 'none');
colormap(grey); %whatever colour map you want to use
surf2patch is used to convert your mesh into polygons that is then passed to patch.

2 Comments

Thanks so much Guillaume. I think so far so good. It is only the 'EdgeColor' I edited from (EdgeColour~which is British English). I can now navigate to what I wanted to achieve. Thanks.
Good morning Guillaume, I appreciate the leverage your answer gave me in my work. Please how can you help me approach it in another way. Suppose I make a plot of the lines using the SL values just like before. Then I set a centreline (zero horizontal) so that there exist a space betwetween the first plot and the centreline set, and between the first line and the second line and so forth. How can I then use the values of AFR which we had earlier on set to represent gray color intensity to fill these spaces between these lines. The purpose of this will enable us use all the rows of AFR thus avoiding end-1 in this AFR(1:end-1, :)). Look at this plot attached and the algorithim. Please just let me know if my description is not clear.
L=5;
Line=['1','2','3','4','5'];
Color=['k','r','m','g','b'];
Baseline=[SL(1,:);zeros(1,302)]; % Setting zero horizontal line.
hold on
plot(BaseLine(1,:)*1000,BaseLine(2,:)*1000,'-.k','DisplayName','centreline');
for j=L:-1:1
plot(SL(j,:)*1000,(h(j,:)*1000),Color(j),'DisplayName',Line(j));
end
legend show
axis([0 350 -100 100]);
grid on
box on
set(gca,'linewidth',1)
xlabel('SL [mm]');
ylabel('h [mm]');

Sign in to comment.

More Answers (1)

DAVID OYUGI
DAVID OYUGI on 6 Jul 2019
I got the way out of my last question. I used the concept of concatenation of matrix. This enabled me to use the earlier code as correctly given by Guillaume with all the rows of AFR as in AFR(1:end, :). Thanks you much Guillaume for your answer.
pdata = surf2patch([Baseline; SL], [Baseline;h], zeros(size([Baseline;h]), AFR(1:end, :)));
figure;
patch(pdata, 'FaceColor', 'flat', 'EdgeColor', 'none');
colormap(grey);

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!