1
votes

I have a matrix which is 100x1 in size. I wish to input each row value of my matrix into a function iteratively. For example, say L1 represents row 1 of my matrix L, L2 row 2, and so on. Say my function which I seek to input each value of L into is denoted Y. Therefore I seek to input L1 into Y to Produce Y1, L2 for Y2 and so on.

I could really do with help on how to implement this in matlab?

accept Code is as follows:

load('logregdata.mat')

%%Data set X is a series of coordinates in two dimensions and t represents class labels. Data set is for a binary classification problem.

u = rand;

[w1,w2] = meshgrid(-5:0.1:5,-5:0.1:5);

w = zeros(2,1);

w_all = zeros(100,2);

%Probabilistic term of logistic classifier prob_t = 1./(1+exp(-[w1(:) w2(:)]*X'));

L = sum(log(prob_t).*repmat(t',numel(w1),1),2);

L= L + sum (log(1-prob_t).*repmat(1-t',numel(w1),1),2);

u = rand;

y = log(L/u);

Thanks for all your help in advance.

2
Why not change the function so that it can support a vector ?obchardon
The function is simply Y=log(L/u), where u is a uniformly distributed random numberuser136754
Your current code would help. Vectorization is highly dependent on the operations being performed. Is u the same for each row of L?beaker
Please show us what you have attempted. It is difficult to ascertain what you're doing wrong without some code to provide context.rayryeng
Thanks for the responses. I have posted the code belowuser136754

2 Answers

0
votes

A 100x1 matrix is just a vector! So you can loop through the entire array like this:

for i = 1:100

      do something with Y(L1)

end
0
votes

In your code u is just a scalar, so you can use simple element-wise operations:

y = log(L./u);

which will give you a vector y in the same size of L such that y(k) = log(L(k)/u)