필터 지우기
필터 지우기

How are editors supposed to know the difference between transpose operators and character arrays?

조회 수: 3 (최근 30일)
For example, with
B = A1 + A2' + A3 + A4'
I am seeing the second half of the RHS highlighted oddly because the editor thinks it's forming a character array.
Wouldn't it be very helpful (and obvious) to allow a different operator to do transposes?? You could always do the PITA way of defining separate variables for each transpose you want to do, but that defeats the point of defining the operator in the first place and you might as well just use transpose() then.
  댓글 수: 5
leka0024
leka0024 2023년 6월 30일
편집: leka0024 2023년 6월 30일
@Steven Lord even better point, thanks. (Although I wasn't proposing to do away with ' as transpose, just to allow users to define an alternate.)
The MATLAB extension for VS Code gets the highlighting correct, so perhaps somehow the jupyter-matlab-proxy group could see how the extension team was able to do it. The ideal thing would be for these two projects to merge into one ultimate tool for MATLAB coding: Notebooks in VS Code. :)
James Tursa
James Tursa 2023년 6월 30일
편집: James Tursa 2023년 6월 30일
I haven't found the apostrophe ' operator to be an issue particularly. But there can be ambiguities with the .' operator with regards to where the period belongs. E.g., in the following:
2i^3.'
Does the period belong with the 3 making the apostrophe ' a ctranspose? Or does the period belong with the .' making it a straight transpose operator? You can run it to see ...
2i^3.'
ans = 0.0000 - 8.0000i
2i^(3.)'
ans = 0.0000 + 8.0000i
(2i^3).'
ans = 0.0000 - 8.0000i
So MATLAB pairs the period with the operator and not the number in this case. Of course, in this particular case if you wanted the ctranspose there is no reason to have the period at all:
2i^3'
ans = 0.0000 + 8.0000i
But my point is you sometimes may need to be careful how you write code with the dot operators such as .' to make the code intent clear to the reader.

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

채택된 답변

Matt J
Matt J 2023년 6월 30일
편집: Matt J 2023년 6월 30일
A cheezy, but compact way you could define an alternative ctranspose operator (temporarily, within a particular workspace) is with a user-defined object that overloads mpower,
classdef myclass
methods
function out=mpower(base,obj)
out=ctranspose(base);
end
end
end % class
>> T=myclass;
>> A=reshape(1:12,3,4)
A =
1 4 7 10
2 5 8 11
3 6 9 12
>>A^T
ans =
1 2 3
4 5 6
7 8 9
10 11 12

추가 답변 (1개)

Matt J
Matt J 2023년 6월 30일
This seems to offer Jupyter Lab integration in a way that preserves Matlab syntax highlighting,
though I cannot find an example there of what happens with A' and A.' expressions.
  댓글 수: 1
leka0024
leka0024 2023년 6월 30일
Thanks @Matt J , I am indeed using jupyter-matlab-proxy, that is the first screenshot above (with Jupyter Lab 3.6, they mention on the repo that highlighting is not yet supported on JL v4).

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

카테고리

Help CenterFile Exchange에서 Integration with Online Platforms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by