trying to rearange a matrix with 2 vectors of indexes and one vector of values

1 回表示 (過去 30 日間)
Kobi
Kobi 2014 年 9 月 15 日
編集済み: Niko 2014 年 9 月 15 日
i have 2 vectors of rows and columns location in the destination matrix and one vector E where all the values are located, and i need to place the values of E in a matrix according to the vectors of the columns and rows
can't think of a solution maybe you can suggest something?
this is the exp file:
the columns or row vectors are rx_pos or tx_pos this is the code:
%%Read exp files and use them in matlab
% Modified: 17/09/2014
clear all
close all
clc
%slCharacterEncoding('ASCII')
fid=fopen('tm.exp');
exp_data=textscan(fid,'%f%f%f%f%f%*f%*f','Headerlines',10 ); % read only col 4 and 5 and skip the first 10 lines
% without loosing prescision!.
fclose(fid);
tx_pos=cell2mat(exp_data(1)); % position of tx antenna 1-36
rx_pos=cell2mat(exp_data(2)); % position of rx antenna
freq=cell2mat(exp_data(3)); % frequancy
reEtot=cell2mat(exp_data(4)); % real part of E_total
imEtot=cell2mat(exp_data(5)); % imaginary part of E_total
clear exp_data
% filter messurements by frequancy
frequancy=4; % [GHz]
loc_f=find(freq==frequancy);
tx_pos=tx_pos(loc_f);
rx_pos=rx_pos(loc_f);
freq=freq(loc_f);
reEtot=reEtot(loc_f);
imEtot=imEtot(loc_f);
Etot=reEtot+1i*imEtot;
%%build the matrix rx_pos x tx_pos
[RX,TX]=meshgrid(rx_pos,tx_pos);
H=Etot(TX,RX);
clc % the Encoding Warning is relevent only for the first 10 rows of the exp file

採用された回答

Niko
Niko 2014 年 9 月 15 日
編集済み: Niko 2014 年 9 月 15 日
LinInd=sub2ind(size(YourMatrix),RowInd,ColInd);
YourMatrix(LinInd)=E;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by