Hey guys is it possible to write a 'for' loop for my code?

My code looks like this
l=[6 7 8 9 10 11 12]'; %cord length
r=(l/Ltest)'; %ratio between lengths and test length(0.75)
% deflection of each cord
l1=(r(:,1)*x);
l2=(r(:,2)*x);
l3=(r(:,3)*x);
l4=(r(:,4)*x);
l5=(r(:,5)*x);
l6=(r(:,6)*x);
l7=(r(:,7)*x);
'x' is a 243 by 1 matrix
Can this code be made much simpler with using a 'for' loop?
Ive only begun to use matlab recently and would greatly appreciate your help.

Answers (2)

>> vec = [6,7,8,9,10,11,12];
>> Ltest = 0.75;
>> x = randi(9,342,1);
>> R = vec / Ltest;
>> out = x * R;

This question is closed.

Tags

Asked:

on 12 Jul 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!