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

1 vue (au cours des 30 derniers jours)
Jon Camilleri
Jon Camilleri le 25 Nov 2015
Commenté : Walter Roberson le 25 Nov 2015
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

Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaires
Jon Camilleri
Jon Camilleri le 25 Nov 2015
How would I code this therefore?
Walter Roberson
Walter Roberson le 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by