What is the easiest way to import a text matrix into Matlab?

조회 수: 1 (최근 30일)
Mehdi
Mehdi 2022년 9월 10일
댓글: Walter Roberson 2022년 9월 10일
HI,
I exported a symbolic matrix from Maple as a text file, and now want to import it to Matlab.
What is the easiest way to import it to Matlab?
Is there any special ready to use function to read it and put in a matrix?
Here I have put two line of that text file, which each line represents each raw of the (2*6) matrix.
x*y*z 1/2*tau[2] sin(x*y*z) ln(x*y*z) tau*exp(x*y*z) sin(x+y)+cos(x+y)
x^2+1 x^2+1/sin(x*y*z) 2*exp(y) tau diff(f(x,y,z),x) int(f(x,y,z),x)

채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 10일
readcell(FileNameGoesHere, 'delimiter', '\t')
or
readtable(FileNameGoesHere, 'delimiter', '\t', 'readvariablenames', false)
Question:
Have you considered using Maple's CodeGeneration[Matlab] function ?
  댓글 수: 7
Mehdi
Mehdi 2022년 9월 10일
편집: Mehdi 2022년 9월 10일
I am looking for 2*6 symbolic matrix exactly similar to what was at Maple.
[x*y*z, 1/2*tau, sin(x*y*z), ln(x*y*z), tau*exp(x*y*z), sin(x+y)+cos(x+y);
x^2+1, x^2+1/sin(x*y*z), 2*exp(y), tau, diff(f(x,y,z),x), int(f(x,y,z),x)];
Walter Roberson
Walter Roberson 2022년 9월 10일
You would need to use str2sym() to convert the entries to symbolic.
However, your input includes '1/2*tau[2]' which is not valid MATLAB symbolic expression.
It also includes ln(x*y*z) -- remember that the MATLAB log is log() not ln()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by