I'm Supposed to write a code that takes a vector from the user and display the statistics of the inserted vector. the answers are supposed to be aligned and to use matrices for each to do so. i keep getting an Unexpected Matlab Error. where is it?

%function [ output_args ] = Untitled( input_args ) %UNTITLED Summary of this function goes here % Detailed explanation goes here function [A] = Stats (~)
disp ('Enter a numerical vector: ') vect = input(' '); %vect = str2num(vect);
% preview [ vect ] = Takes ( prompt )
max_vect = max(vect);
min_vect = min(vect);
range_vect = range(vect);
median_vect = median(vect);
mean_vect = mean(vect);
std_vect = std(vect);
var_vect = var(vect);
kurt_vect = kurtosis(vect);
prctile1_vect = prctile(vect, 25);
prctile3_vect = prctile(vect, 75);
IQR_vect = prctile(vect,75)-prctile(vect,25);
R = [ max_vect min_vect range_vect median_vect mean_vect std_vect var_vect kurt_vect prctile1_vect prctile3_vect IQR_vect];
T = [ 'Maximum ' ; 'Minimum '; 'Range ' ; 'Median ' ; 'Mean '; 'Std ' ; 'Variance '; 'Kurtosis '; 'Qrt1 '; 'Qrt3 '; 'IQR ' ];
W = num2str®;
A = [T W'];
end

2 Comments

What line is throwing the error?
Please copy all the red text in the Command Window, including the line that threw the error, and paste it to a Comment here.
EDU>> Stats Enter a numerical vector: 2 6 3 8 3 1 2 6 3 8 3 1 | Error: Unexpected MATLAB expression.
This is it. i thought my code seemed right, not sure though.

Sign in to comment.

Answers (1)

It's your input; a valid Matlab expression to load a vector must include the []...
>> z=1 2 3
z=1 2 3
|
Error: Unexpected MATLAB expression.
>> z=(1 2 3) % parens don't cut it, either...
z=(1 2 3)
|
Error: Unexpected MATLAB expression.
>> z=[1 2 3] % need the square brackets for proper syntax.
z =
1 2 3
>>
See
doc input % for details; it uses EVAL on the expression typed in
Also, I'd suggest using the integral prompt string with input rather than disp; it's simply excessively wordy to use two functions when one will do..

Categories

Asked:

on 25 Mar 2015

Answered:

dpb
on 25 Mar 2015

Community Treasure Hunt

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

Start Hunting!