How do I enter a string input that will later be used in a title?

1 次查看(过去 30 天)
Essentially, why does the follow code not work?
data = data(:, 1:2); %Condenses matrix by removing unused columns
Savedata = data; %Saves data before manipulation.
data = data*25.4; %Converts to millimeters
data(1:11, :) = []; %Removes datum set up measurements
N = length(data(:, 1)); %Assigns to N the number of entries in column 1
%If the data is formatted incorrectly (a wrong number of rows), then this code will inform the user of this problem.
if mod(N,3) ~= 0
clc
disp('Clear variables and reload data.')
disp('There is an incorrect number of rows')
return
end
data = data(3:3:N, :); %Removes 'point' information. Now there are only distance measurements (x and y) in the matrix
dat = data;
%Inputs
diename = input('Enter the name of the die: ', 's'); %Name of die for graphical output
nom = input('Enter the nominal value for the separation distance (mm): '); %Allows the user to enter the nominal value of separation.
tol = .00254;
numstd = 5; %Number of standard deviations for outlier removal
.
.%morecode
.
postnomtable(postnomtable==0)=NaN;
figure
pcolor(postnomtable)
colormap(GColorMap); %GColorMap has already been made
colorbar;
title('Figure 2: Cell Separation Distance (mm) - Difference between Nominal and Measured for a DPF Die %s Measured on the OGP', diename)
Here's the error I'm getting:
Enter the name of the die: asdf
Enter the nominal value for the separation distance (mm): .31
Is the skin included in this measurement? n
??? Error using ==> title at 29 Incorrect number of input arguments
Error in ==> title at 23 h = title(gca,varargin{:});
Error in ==> NotRotationandSkin01 at 338 title('Figure 2: Cell Separation Distance (mm) - Difference between Nominal and Measured for a DPF Die %s Measured on the OGP', diename)
>>

采纳的回答

Jan
Jan 2012-7-19
编辑:Jan 2012-7-19
The meaning of "Incorrect number of input arguments" seems to be clear: title accepts one string only.
title(sprintf(['Figure 2: Cell Separation Distance (mm) - ', ...
'Difference between Nominal and Measured for ', ...
'a DPF Die %s Measured on the OGP'], diename));
  2 个评论
Andrew
Andrew 2012-7-19
That worked. Thanks. Awesome picture, btw.
Why does it only accept one string?
Jan
Jan 2012-7-19
The inputs of title are explained in doc title. There you find "title('string')". Inserting a another string at the %s key is a task for sprintf and including this into title would be an over-featuring, which would make the parsing of the other input arguments extremely complicated.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by