How do I multiply a column in a matrix by a range of values?

12 views (last 30 days)
So I've attached my code below, what I want to do is hopefully fairly self-explanitory but I don't know if it can be done or not... I was to multiply the third column in the latin hypercube sample by a range from -12 to +30 in order to get values for the Spark range. I started off thinking I would just use 42 (the difference between the two numbers but this doesn't give me the data I need (obviously) so now I'm not sure how to solve this.... I'm doing a module for uni that involved a lot of coding and I have no experience at all with Matlab so all answers need to be explained please!!! :)
sfd = lhsdesign(100,3); %Creates a Latin Hypercube sample of 100 points with 3 variables
speed_pts = sfd(:,1)*4000; %Separates sample out into columns and assigns engine speed to column 1. Engine speed is set at 4000
load_pts = sfd(:,2)*1.5; %Assigns load to column 2. Load is set at 1.5
spark_pts = sfd(:,3)*[-12:30]; %Assigns spark range to column 3. Spark range is set from -12 to +30
All help is greatly appreciated!!

Answers (1)

Star Strider
Star Strider on 22 Mar 2019
I am not at all certain what result you want.
Try these:
spark_rng = linspace(-12, 30, numel(sfd(:,3))); % Spark Range Vector
spark_pts = sfd(:,3) .* spark_rng'; % Linear
spark_pts = sfd(:,3) .* spark_rng(randperm(numel(sfd(:,3))))'; % Random
They create ‘spark_rng’ as a (100x1) vector linearly spanning (-12,30), then either uses that directly or randomises it, then multiplies that (linear or random) vector by ‘sfd(:,3)’.
If this is not what you want (I am guessing here), please provide more details.

Categories

Find more on Networks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!