Specify colour when using script ipvd.m

조회 수: 1 (최근 30일)
Jenny
Jenny 2016년 5월 10일
답변: Matt Cohen 2016년 5월 16일
I am using the code attached (ipvd.m) to generate a progressive vector diagram for different data sets on the same figure.
How can I specify the colour of the line automatically (rather than using the plot editor manually) ?
My code calls the ipvd.m as follows:
figure
ipvd(uCurr5m/1000,vCurr5m/1000);
hold on;
ipvd(uCurr15m/1000,vCurr15m/1000);
ipvd(uCurrspred/1000,vCurrspred/1000);
ipvd(uCurrbunn/1000,vCurrbunn/1000);
I tried the following (which did not work)
p = ipvd(uCurr5m/1000,vCurr5m/1000);
set(p,'color','r');
Any help would be greatly appreciated.
Jenny

답변 (1개)

Matt Cohen
Matt Cohen 2016년 5월 16일
Hi Jenny,
I understand that you are interested in automatically specifying and modifying the color of the line in the plot generated by the function "ipvd.m".
You can accomplish this task by making a minor modification to the function's code. In the last line of code in "ipvd.m", you should return the handle to the quiver object, as follows:
q = quiver(posX(1:n),posY(1:n),vx(:),vy(:),0);
Right now, this function does not appear to return any variables, even though you are treating it like it is. You should output this quiver object from the function:
function q = ipvd(vx,vy,xo,yo)
Just like other graphics objects in MATLAB, you can modify various property values through the quiver's handle. I have included a documentation link that provides information about the quiver series properties.
For example, the following code modifies the color of the quiver's line:
q = ipvd(1:10, 1:10);
q.Color = 'green'; % One syntax for modifying color
set(q,'Color','red'); % Another syntax
I hope this helps.
Matt

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by