how to perform a vectorized operation with an array of multiple random numbers?
2 次查看(过去 30 天)
显示 更早的评论
I want to perform multiple vectorized operations with the following numbers:
v_tank = 10.*rand(100,1)+35;
The code is:
clear all; close all; clc;
hold on
v_tank = 10.*rand(10,1)+35;
v_trailertank = 80;
v_trailer = 100;
t_loading = 1/12;
t_unloading = 1/12;
L = 400;
%the vector operations:
x = 100:0.01:150;
t_tank1=(t_loading+(x/v_trailertank)+t_unloading)+((L-x)/v_tank);
t_tank2=(t_loading+(x/v_trailertank)+t_unloading)+x/v_trailer+(t_loading+L/(v_trailertank)+t_unloading);
t_operation=max(t_tank1,t_tank2);
It can be seen that v_tank in the operation is an array of 100 random numbers. I want the vectorized operation be executed for all values of v_tank. I was thinking about a for-loop, but is impossible because v_tank are not positive integers. Please help.
2 个评论
Walter Roberson
2019-9-28
Change your / to ./
If you were using * or ^ then you would change those to .* and .^
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!