1
0

M2S.m 987 B

123456789101112131415161718192021222324252627
  1. %{
  2. Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
  3. This file is part of GratingFMM.
  4. GratingFMM is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. GratingFMM is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
  14. %}
  15. %% convert a matrix to S-matrix format
  16. function S = M2S(M)
  17. no = size(M,1)/2;
  18. S = zeros(no,no,2,2);
  19. S(:,:,1,1) = M(1:no,1:no);
  20. S(:,:,1,2) = M(1:no,(no+1):(2*no));
  21. S(:,:,2,1) = M((no+1):(2*no),1:no);
  22. S(:,:,2,2) = M((no+1):(2*no),(no+1):(2*no));
  23. end