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

3 views (last 30 days)
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

Accepted Answer

Niko
Niko on 15 Sep 2014
Edited: Niko on 15 Sep 2014
LinInd=sub2ind(size(YourMatrix),RowInd,ColInd);
YourMatrix(LinInd)=E;

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!