Here is how to do this:
y0=[0 0]
tspan=[0,100]
w=0.1
odefun=@(t,y) [y(2);cos(w*t)+y(2)+3*y(1)];
[t1,y1]=ode45(odefun,tspan,y0);
w=1.0
odefun=@(t,y) [y(2);cos(w*t)+y(2)+3*y(1)];
[t2,y2]=ode45(odefun,tspan,y0);
w=10.0
odefun=@(t,y) [y(2);cos(w*t)+y(2)+3*y(1)];
[t3,y3]=ode45(odefun,tspan,y0);
Now you have three solutions, t1,y1, t2,y2, and t3,y3 for values of w=0.1, 1.0 and 10.0.
When you define an anonymous function using a constant (in this case w) the constant becomes embedded in the function. That's why you have to re-define the function when you change the value of w.
Note that y1, y2, and y3 contain two columns each. You can plot these using:
figure;
plot(t1,y1(:,1),'r');
hold on;
grid on;
plot(t2,y2(:,1),'b');
plot(t3,y3(:,1),'g');
legend('w=0.1','w=1.0','w=10.0');
The notation y1(:,1) y2(:,1) y3(:,1) indicates the first column. If you want to plot the second column, change the 1 to a 2.