hi all, I am working on combining two .mat files which have same variables as structures.

i have two .mat files, with same variable(Offset_Results) which is a structure. The structure Offset_Results has many fields of which few are arrays. one of the array is Freq_MHz. One .mat file has freq from 2000 to 4360MHz and the other from 2560 to 2660 MHz. I want to override the later into the first i.e. from 2000 to 2559 from first, 2560 to 2660 from second and from 2661 to 4360 again from the first file and store the entire result into a new .mat file.
Please help me in this regard.

 Accepted Answer

If your arrays are vectors, I think the code below would do the job. Maybe it can be done in a neater fashion, but this works for me. In this example, vector A is your first array and vector B is your second array. Please note that it's mainly the code that follows the declaration of "count", that does the job.
% Create two sample input vectors
A = rand(1,20);
B = [0.25:0.05:0.50]
% Sort the vectors (B is already sorted)
A_sorted = sort(A)
% Find minimum and maximum value in the second vector
B_min = min(B);
B_max = max(B);
% Determine where in vector A (sorted), the B vector should be positioned
count = [1:length(A)];
start_location = floor(interp1(A_sorted,count,B_min));
end_location = ceil(interp1(A_sorted,count,B_max));
% Place vector B at the correct place in vector A
Result = [A_sorted(1:start_location) B A_sorted(end_location:end)]

More Answers (0)

Products

Asked:

on 18 Nov 2013

Commented:

on 19 Nov 2013

Community Treasure Hunt

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

Start Hunting!