필터 지우기
필터 지우기

Converting inputdlg entries to symbols in a matrix

조회 수: 2 (최근 30일)
Drilon Ferra
Drilon Ferra 2021년 7월 8일
답변: Walter Roberson 2021년 7월 8일
Code for non-symbol case:
Matrices = inputdlg({'Matrix 1', 'Matrix 2'})
Matrix1 = str2num(Matrices{1})
Matrix2 = str2num(Matrices{2})
Product = Matrix1*Matrix2
I have tried the following but it does not work.
str2sym(Matrices{1})
I want the user to be able to enter somethig like a 40; c 20 and have this converted to a matrix whilst recognising the letters as symbolic values.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 7월 8일
You need to have [] around the entries. str2sym() will not assume that a space is to indicate a list.
Matrices = {'40', 'c 20'}
Matrices = 1×2 cell array
{'40'} {'c 20'}
str2sym(Matrices{1})
ans = 
40
str2sym("["+ Matrices{2}+"]")
ans = 

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by