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

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Array Geometries and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by