Hi Guys,
I'm trying to read some data into Matlab. This is what I've done so far.
>> selwoodData = zeros(53);
Now what I would like to do is pick off each column into a column vector variable. Is there a way to do this without hard coding it. I was thinking of setting up a loop that read each of the 53 columns into different variables, but I'm not sure how I would change the variable name each time. Any help would be appreciated.
Thanks

2. Originally Posted by notPrime
Hi Guys,
I'm trying to read some data into Matlab. This is what I've done so far.
>> selwoodData = zeros(53);
Now what I would like to do is pick off each column into a column vector variable. Is there a way to do this without hard coding it. I was thinking of setting up a loop that read each of the 53 columns into different variables, but I'm not sure how I would change the variable name each time. Any help would be appreciated.
Thanks
I'm not at a machine that I can run Matlab on at present so can't check the syntax, but something like the following should do the trick:

Code:
sz=size(selwoodData)

for idx=1:sz(2)
eval(['rootname',num2str(idx),'=selwoodData(:,idx)']);
end

3. Thanks a lot. I have another question (Sorry, I literally started using Matlab last week). I have two m files fitness and DoIt. In DoIt, I have:
...Some code
fitness(gene2,gene3,gene4,gene5,gene6,actualYValue s,measureOfFit1)
In fitness, I have:
%This function measures the fitness of our chromosome by comparing the predict values to the
%actual values. The measure of fit is the square of the pearson correlation coefficient.

function[measure] = fitness(x1, x2, x3, x4, x5,yValues,fitnessValue)
%Here we form the matrix and carry out the linear regression calculations
firstColumn=ones(29,1);
theMatrix = [firstColumn, x1, x2, x3, x4, x5];
c=inv(transpose(theMatrix)*theMatrix)*transpose(th eMatrix);
%Now we will multiply the transpose of the c matrix by the the transpose of theMatrix to
%calculate our predicted y values. Using linear regression.
finalMatrix = transpose(transpose(c)*transpose(theMatrix));
predictedYValues = finalMatrix*yValues;
measure = linreg(predictedYValues, yValues);
fitnessValue=measure;

I'm trying to get the fitness function to reflect the changes in the fitnessValue done in the fitness function back to the DoIt function. How would I do this? Is there anything like the ampersand in C?

4. Originally Posted by notPrime
Thanks a lot. I have another question (Sorry, I literally started using Matlab last week). I have two m files fitness and DoIt. In DoIt, I have:
...Some code
fitness(gene2,gene3,gene4,gene5,gene6,actualYValue s,measureOfFit1)
In fitness, I have:
%This function measures the fitness of our chromosome by comparing the predict values to the
%actual values. The measure of fit is the square of the pearson correlation coefficient.

function[measure] = fitness(x1, x2, x3, x4, x5,yValues,fitnessValue)
%Here we form the matrix and carry out the linear regression calculations
firstColumn=ones(29,1);
theMatrix = [firstColumn, x1, x2, x3, x4, x5];
c=inv(transpose(theMatrix)*theMatrix)*transpose(th eMatrix);
%Now we will multiply the transpose of the c matrix by the the transpose of theMatrix to
%calculate our predicted y values. Using linear regression.
finalMatrix = transpose(transpose(c)*transpose(theMatrix));
predictedYValues = finalMatrix*yValues;
measure = linreg(predictedYValues, yValues);
fitnessValue=measure;

I'm trying to get the fitness function to reflect the changes in the fitnessValue done in the fitness function back to the DoIt function. How would I do this? Is there anything like the ampersand in C?
Try calling code:

Code:
fitnessvalue=fitness(  ..... )
where the fitness function returns measure rather than modifies fitnessvalue:

Code:
function [measure] = fitness(x1, x2, x3, x4, x5,yValues,fitnessValue)
%Here we form the matrix and carry out the linear regression calculations

firstColumn=ones(29,1);
theMatrix = [firstColumn, x1, x2, x3, x4, x5];
c=inv(transpose(theMatrix)*theMatrix)*transpose(theMatrix);
%Now we will multiply the transpose of the c matrix by the the
%transpose of theMatrix to
%calculate our predicted y values. Using linear regression.
finalMatrix = transpose(transpose(c)*transpose(theMatrix));
predictedYValues = finalMatrix*yValues;
measure = linreg(predictedYValues, yValues);
CB