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?

1 次查看(过去 30 天)
%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 个评论
Star Strider
Star Strider 2015-3-25
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.
Anfal Hussain
Anfal Hussain 2015-3-25
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.

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2015-3-25
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..

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by