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 Comment

Stephen23
Stephen23 on 6 Jan 2017
Edited: Stephen23 on 6 Jan 2017
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.

Sign in to comment.

Answers (2)

clc;
clear all;
a=input('enter a:');
title = sprintf('The value of a is:%f',a)
Stephen23
Stephen23 on 6 Jan 2017
Edited: Stephen23 on 6 Jan 2017
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

Asked:

on 6 Jan 2017

Edited:

on 6 Jan 2017

Community Treasure Hunt

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

Start Hunting!