I am very new to matlab. Please state Why I am getting Subscripted assignment dimension mismatch error

1 次查看(过去 30 天)
clear
clc
close all
%% defination
m= 750; % mass of the system in kg
k= 50000; % Stiffness of system in N/m
c= 1000; % damping coefficient Ns/m
time= 0:0.01:1; %time in sec
x_0=0.01; % displacement intial condition
x_dot_0= 0; % velocity initial condition
y_0=0.01; % displacement intial condition
y_dot_0= 0; % velocity initial condition
syms x(t)
syms y(t)
D1x= diff(x,1);
D2x= diff(x,2);
D1y= diff(y,1);
D2y= diff(y,2);
%% computing
x= dsolve(m*D2x+k*x==0,x(0)==x_0, D1x(0)==x_dot_0,'t');
y= dsolve(m*D2y+k*y+c*D1y==0,y(0)==y_0, D1y(0)==y_dot_0,'t');
x_fun=matlabFunction(x) % to save solved function values
x_dot_fun = matlabFunction(diff(x))
y_fun=matlabFunction(y)
y_dot_fun = matlabFunction(diff(y))
x_t=x_fun(time);
y_t=y_fun(time);
u_t=x_dot_fun(time);
v_t=y_dot_fun(time);
difference=x_fun(t)-y_fun(t)
%% plotting
% plot parameters
clr=[236/255 237/255 237/255]; % standarad RGB code
unts='normalized'; % Screen resolution percentage
lnwidth=2; % line width of the plot
fnts=22; % font size in percent
pos_fig=[0.01 .1 0.98 0.8];
title_graph='Displacement and velocity vs time';
xlabel_graph='time' ;
ylabel_graph(1)='dispalcement';
ylabel_graph(2)='velocity';
%% plotting
fig= figure('colour',clr,'units',unts,'position',pos_fig);
[axes_graph, Line1,Line2] = plotyy(time,x_t,time,v_t);

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2019-6-1
In my version of matlab I have to assign strings using the string function
ylabel_graph(1) = string('dispalcement');
ylabel_graph(2) = string('velocity');
Maybe your version also supports double-quotes for string-generation:
ylabel_graph(1) = "dispalcement";
ylabel_graph(2) = "velocity";
I personally (straddling older matab-versions) would delay inserting variables of string-type a couple of years and stick with
cell-arrays of char-arrays to keep backwards compatibility:
ylabel_graph{1} = 'dispalcement';
ylabel_graph{2} = 'velocity';
HTH

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by