how to get value from work space

hello I am working on project . for exmaple i have this code
clc;
clear all;
a=input('enter a:');
title=(' the value of a is :');
I want the title to show the value of the variable a that I insert. how to do it ?

1 个评论

Do not call your variable title, because then you will not be able to call the title function. For the same reason you should never use variable names cell, length, size, i, j, etc. Use which to check if a name is already used.

请先登录,再进行评论。

回答(2 个)

clc;
clear all;
a=input('enter a:');
title = sprintf('The value of a is:%f',a)
Stephen23
Stephen23 2017-1-6
编辑:Stephen23 2017-1-6
It is highly recommended to use the non-evaluating syntax of input, which is faster and much more secure:
>> str = input('input value a: ','s');
input value a: 5.6
>> val = str2double(str)
val = 5.6000
And put it into your title using either of these:
>> txt = sprintf('the value of a is %s',str)
txt = the value of a is 5.6
>> txt = sprintf('the value of a is %s',num2str(val))
txt = the value of a is 5.6

类别

Community Treasure Hunt

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

Start Hunting!

Translated by