How do I put all my vectors through the same operation?

It sounds like a very simple task, yet I cannot figure out how to do this. I have got 18 vectors, and I'm trying to divide them all by the same number, without typing it all out manually. I was thinking about using a for-loop but the vectors don't contain any index. Any advice? Thanks in advance! Here are all the vectors. I'm trying to divide them by the given constant ' l ':
l = 0.50 *10^-3;%m%
Tf1 = [36.91 34.10]; %s%
Tr1 = [11.04 9.75];
Tf2 = [25.75 27.60 27.53 23.87];
Tr2 = [3.78 3.31 2.22 2.94];
Tf3 = [19.37 22.03 25.12 21.75];
Tr3 = [5.66 6.68 7.78 8.15];
tf4 = [33.19 35.00 38.50 31.12];
Tr4 = [13.91 10.94 14.37 13.22];
Tf5 = [16.00 17.16 17.53 17.60];
Tr5 = [10.97 12.03 12.12 12.28];
Tf6 = [11.63 11.20];
Tr6 = [11.18 12.16];
Tf7 = [18.10 20.25];
Tr7 = [31.00 28.35];
Tf8 = [17.59 21.72 25.15 21.66];
Tr8 = [9.59 9.68 9.03 8.18];
Tf9 = 24.32;
Tr9 = 8.61;

1 Comment

"I have got 18 vectors"
And that is the cause of your problems:
"Any advice?"
Store them all in a cell array. Then use very basic indexing. Easy. Don't make it more complex than that.

Sign in to comment.

Answers (1)

l = 0.50e-3;%m%
% store the vectors Tf1, Tr1, Tf2, ..., Tr9, in a 9x2 cell array
% (so that, e.g., what you called Tf6 is now T{6,1} and
% what you called Tr8 is now T{8,2}, etc.):
T = { ...
[36.91 34.10], [11.04 9.75]; ...
[25.75 27.60 27.53 23.87], [3.78 3.31 2.22 2.94]; ...
[19.37 22.03 25.12 21.75], [5.66 6.68 7.78 8.15]; ...
[33.19 35.00 38.50 31.12], [13.91 10.94 14.37 13.22]; ...
[16.00 17.16 17.53 17.60], [10.97 12.03 12.12 12.28]; ...
[11.63 11.20], [11.18 12.16]; ...
[18.10 20.25], [31.00 28.35]; ...
[17.59 21.72 25.15 21.66], [9.59 9.68 9.03 8.18]; ...
24.32, 8.61; ...
};
% divide each vector by the constant l (and store it back in T):
for ii = 1:numel(T)
T{ii} = T{ii}/l;
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2023a

Tags

Asked:

on 6 Dec 2023

Answered:

on 7 Dec 2023

Community Treasure Hunt

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

Start Hunting!