how to multiply vector and matrix

Hello there,
i need your help. i got two question
1. i have a :
col=1;
t=0:(1.5/10):1.5;
for i=1:length(t)
if col<11
m1=magnitudeL(1,col);
m2=magnitudeL(1,col+1);
m3=m2-m1;
acceL(1,col)=[m3/((1.5/10).^2)];
end
col=col+1;
end
how can i plot the graph of plot(t,accel) ? everytime its return error =
Error using plot Vectors must be the same lengths.
i understand the array not same, but i can't modify * acceL * to be same as t.
2. i have a
Lversor=[x;seatoff;z];
i need this vector to multiply with f and M .i.e :
forceMa=m*acceL*Lversor;
where m is a constant and acceL is an array.acceL is same like coding above. is it posible to do that?
thank you.

댓글 수: 2

Roger Stafford
Roger Stafford 2014년 12월 24일
In 1. how would you suggest a plot be made using more 't' values than 'acceL' values, namely 11 against only 10? What would such a plot look like?
In 2. where you write "m*acceL*Lversor" the second asterisk sign is understood in matlab to be matrix multiplication, and this always requires that the number of columns in 'acceL' be the same as the number of rows in 'Lversor'. Otherwise Matlab will always give you an error message. I suggest you specify precisely what numerical computations you want to see used to obtain 'forceMa' without using matlab syntax and see if we can come up with an algorithm that accomplishes it.
1. i need it, because in 'm3' i need to get the different value of 'magnitudeL[2]-magnitudeL[1]'. and that value to plot graph 'acceL' vs 't'.
2.it's a formula derive from an equation.
F=ma.L versor - mg.L Versor

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 24일

1 개 추천

Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
numberOfElements = 11; % Whatever.
magnitudeL = rand(1,numberOfElements) % Sample data
t= linspace(0, 1.5, numberOfElements)
acceL = zeros(1, numberOfElements-1);
for k = 1 : numberOfElements-1
m1 = magnitudeL(1,k);
m2 = magnitudeL(1,k+1);
m3 = m2 - m1;
acceL(k) = m3 / ((1.5/10).^2);
end
plot(t, magnitudeL, 'bo-');
grid on;
hold on;
plot(t(1:length(acceL)), acceL, 'rd-');

댓글 수: 3

thank you, i manage to plot the graph.
would you mind tellig me what this line acctually do? coz, i learning matlab coding by myself.
plot(t(1:length(acceL)), acceL, 'rd-');
would you mind help me with the second question?
thank you and happy holiday.
Image Analyst
Image Analyst 2014년 12월 25일
acceL is one element shorter than t so I can't plot it vs. t - I have to plot it versus all but the last element of t, which is what t(1:length(acceL)) gives me. 'r' meand red. 'd' means diamond. '-' means to put a solid line between the data points.
m
m 2014년 12월 30일
i have change the coding, and now i have more element in acceL compare to t, but i want to ommit the first element of acceL like :
plot( t,acceL ( but accel start with element[1]))
thanks

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

m
m
2014년 12월 24일

댓글:

m
m
2014년 12월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by