0
M = round(csvread('noob.csv'))
save projectDAT.dat M -ascii
load projectDAT.dat
mat = (projectDAT)
sum_of_rows(mat)
plotthegraph
这是我的主要脚本。我有一个excel文件,它在matlab中打开了一个20 x 20的矩阵。现在我不得不在这个主题中调用一个函数,它将为我找到一行中的元素的总和并将它们放入列向量中。这里是我的功能:通过调用函数绘制图形
function sumRow = sum_of_rows(mat)
[m n] = size(mat);
sumRow = zeros(m,1);
for i = 1:m;
for j = 1:n;
sumRow(i) = sumRow(i) + mat(i,j);
end
end
vec = sumRow;
end
我需要绘制使用此列向量的线图。我应该从主脚本中调用一个函数。该函数应该能够接受来自sum_of_rows函数的输入。我试图这样做:
function plotthegraph(~)
% Application for plotting the height of students
choice = menu('Choose the type of graph', 'Plot the data using a line plot', 'Plot the data using a bar plot');
if choice == 1
plot_line(sum_of_rows)
y = sum_of_rows
x = 1:length(y)
plot(x,y)
title('Bar graph')
xlabel('Number of characters')
ylabel('Number of grades')
elseif choice == 2
plot_bar(sum_of_columns)
end
虽然它不工作。有人可以帮助我,我真的很感激它。谢谢。
谢谢你这么多 – Logan
嘿。你的代码工作得很好。但是当我关闭matlab并再次打开它以再次尝试代码时,它会一直说: ???未定义的函数或变量'sumRow'。 – Logan
加载project.dat再次发出sumRow = sum(mat,2);.当matlab关闭时,环境被清除 – brodoll