Help with loops and plotting with functions
2 views (last 30 days)
Show older comments
I have this assignment, and I'm stuck on making this function. This is what we were given:
This function has a finElems parameter and doesn't return anything. It plots all the temperature values found in the finElems array. You can see my example plot below. To plot a color, use a statement like this:
plot(colNum, numRows-rowNum, 's', 'Color', color,... 'MarkerFaceColor', color, 'MarkerSize', 20);
In order to use this statement you should create a few variables:
• colNum: This is the current column number. You will iterate through all the columns in the array, so store the current column number in this variable.
• rowNum: Same as colNum, except it's the current row number.
• color: This is the color of the current finElems element as determined by the function tempToColor.
I found it necessary to use the expression numRows - rowNum so that the bottom row of the array (the highest numbered row) appears as the bottom row on the graph. Otherwise the fin appears upside down in the graph. Use this outline for the function:
function plotFin(finElems)
hold on;
% iterate through all the rows:
% iterate through all the columns: (this is a loop within a loop)
% Use the tempToColor function to get the temperature.
% Plot the temperature color.
% end
% end
axis equal tight;
axis([0 (numCols+1) -1 numRows]);
hold off;
end
So far, what I have for the plotFin function is:
function plotFin(finElems)
hold on;
for rowNum=1:10
for colNum=1:20
tempToFin(temp)
plot(colNum, numRows-rowNum, 's', 'Color', color,...
'MarkerFaceColor', color, 'MarkerSize',20);
end
end
axis equals tight;
axis([0 (numCols+1) -1 numRows]);
hold off
end
And what I have for my tempToColor function is:
function color = tempToColor(temp)
persistent map
if isempty(map)
map = jet(steamTemp-coolantTemp+1);
end
color=map(temp+1,:)
end
I'm stuck mainly on trying to use tempToColor to get the temperature to plot it. Thanks in advance for your help!! :D
0 Comments
Accepted Answer
Adam
on 13 Nov 2014
What exactly are you stuck on?
For a start though you are not assigning the output of tempToColor to a variable so your 'color' variable in plotFin will be unassigned.
Is that your only problem or are there others?
7 Comments
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!