How can I call a previous user inputted variable to a string array?

1 ビュー (過去 30 日間)
Gavin Thompson
Gavin Thompson 2021 年 9 月 3 日
コメント済み: Gavin Thompson 2021 年 9 月 3 日
newMaterial = input('Please enter a new material name:','s');% Copper
Materials = ["Aluminum";"Cadmium";"Iron";"Tungsten";"newMaterial"];
TotalMat = length('Materials')
When I try to run my script instead of showing Copper (which is the variable I input in the command window, it shows up in my string array as newMaterial. How can I get my script to recognized that im calling the user inputted variable. I cannot just say Copper in the string array because I need this script to work with multiple other user inputted materials.
Also if it helps, when I calculate length of this string array I get an output of 9 instead of 5.


Chunru 2021 年 9 月 3 日
Mind the difference between string and char:
newMaterial = string(input('Please enter a new material name:','s')) ;% Copper
Materials = ["Aluminum"; "Cadmium"; "Iron"; "Tungsten"; newMaterial]
TotalMat = length(Materials)
  1 件のコメント
Gavin Thompson
Gavin Thompson 2021 年 9 月 3 日
This solved both issues I had I really appreciate it!


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by