Help with loops and plotting with functions

2 次查看(过去 30 天)
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

采纳的回答

Adam
Adam 2014-11-13
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 个评论
Andrew Ardolino
Andrew Ardolino 2014-11-14
okay, now I get errors when I try to run that, but I'm working on it. Do you think you'd be able to help me with the next function also? My teacher doesn't email us back and the homework he gives us are way past what he teaches us in class.
Next function should be:
6.8. Function placeAirTemp
This function has one parameter: the fin element array, and it returns a fin element array. In this function you must place the air temperature values along the top edge (row 1) of the array, and down the left and right edges of the array (the right edge is column numCols). Use the value from the airTemp function.
I have no idea where to even begin with this one:P
Andrew Ardolino
Andrew Ardolino 2014-11-14
I know I'd need to do something to make it go from 1:numRows and 1:numCols But I'm not sure how to go about doing that.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by