The learning problem in MATLab, how do I code it?

1 view (last 30 days)
I am trying to convert information from a CSV file into data that I can plot to a graph but I have some data conversion problems.
Using a for loop so far has proven unsuccessful unfortunately.
function [average] = classifyIris(file)
% Detailed explanation goes here
load(file);
average = sum(file)/numel(file);
for i = 1:size(iris_data)
double tmp1 = str2double(iris_data{i,i};
end;
end
I am working towards coding a machine learning classification algorithm.
Further reading
  1. http://www.mathworks.com/help/matlab/ref/linspace.html
  2. http://www.mathworks.com/matlabcentral/newsreader/view_thread/147624

Accepted Answer

Walter Roberson
Walter Roberson on 25 Nov 2015
You are passing a string in to the routine that is the name of a file that you load. You then calculate the average of the string, not of the content of the file.
You should use csvread() or xlsread() or you should use load() with an output argument such as
data = load(file);
then you can calculate mean(data(:)) and so on.
You appear to have a variable named iris_data defined in a different scope. Or possibly your load() is not of a csv file and instead is of a .mat file and you are "poofing" variables into existence. Use the output form of load() instead of doing that.
  2 Comments
Walter Roberson
Walter Roberson on 25 Nov 2015
Where is the content for iris_data coming from? Why are you doing any calculation with it, considering that you are calculating your only return variable, "average", before that line? Does "file" refer to a csv file or to a .mat file? If it is a csv file then how many items are there per line? Do you want the average by row or by column or the overall average? If it is a .mat file then what are the names of the variables stored in the file?

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings 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!