# After running the code, the arrays that should have the calculated values for all the rows are still empty?

2 views (last 30 days)
Arpan Ojha on 29 Nov 2021
Answered: Prachi Kulkarni on 3 Dec 2021
I have this code that I am trying to loop for each row. After running the code, the arrays that should have the calculated values for all the rows are still empty. When I open the arrays from the workplace they are still empty with a value of 0 in one cell.
data_path = 'Data\';
file_name = 'Arpan_BINOCULAR-20200119-fft-0.csv';
file_path = strcat(data_path,file_name);
rows = size(data_i, 1);
all_rows_longitudes = zeros(length(rows),1);
all_rows_latitudes = zeros(length(rows),1);
all_rows_peak_velocities = zeros(length(rows),1);
all_rows_peak_velocities_errors = zeros(length(rows),1);
all_rows_intensities = zeros(length(rows),1);
for row = 1:rows
data = data_i(rows, :);
RA_H = data(4);
RA_M = data(5);
RA_S = data(6);
Div1 = cos(DEC)*sin(RA-RA_NGP);
Div2 = cos(DEC_NGP)*sin(DEC)-sin(DEC_NGP)*cos(DEC)*cos(RA-RA_NGP);
l = l_NCP - atan2(Div1, Div2);
if longitude < 0
longitude = longitude + 360;
end
if ((longitude >= 0) && (longitude <= 90) || (longitude >=270) && (longitude <= 360)) && ((latitude >= -20) && (latitude <= 20))
x_data = (1:8192);
y_data = data(:, 10:end);
linear_y = 10.^(T./10);
frequency_rest = data(:, 7);
x_frequency = linspace(frequency_rest-1.25, frequency_rest+1.25, 8192);
x_1 = x_frequency(1500);
x_2 = x_frequency(6500);
y_1 = linear_y(1500);
y_2 = linear_y(6500);
m = ((y_1-y_2)/(x_1-x_2));
c = y_1 - m*x_1;
y_fit = m.*x_frequency + c;
y_fitted = linear_y-y_fit;
y_focussed = y_fitted(condition);
y_smooth = smooth(radial_vel_focussed, y_focussed, 0.1, 'rloess');
y_smooth = y_smooth(order);
[pks, locs, w, p] = findpeaks(y_smooth, radial_vel_focussed, 'MinPeakProminence', 0.02e-10);
peak_velocity = max(locs);
peak_data = [pks, locs', w', p];
if isempty(peak_data)
peak_data = zeros(1,4)
peak_velocity = 0
end
[a b] = find(peak_data == peak_velocity);
rightmost_peak_data = peak_data(a, :);
rightmost_pks = rightmost_peak_data(1);
rightmost_locs = rightmost_peak_data(2);
rightmost_w = rightmost_peak_data(3);
rightmost_p = rightmost_peak_data(4);
all_rows_latitudes(row) = latitude;
all_rows_longitudes(row) = longitude;
all_rows_peak_velocities(row) = peak_velocity;
all_rows_peak_velocities_errors(row) = rightmost_w;
all_rows_intensities(row) = rightmost_w*rightmost_p;
end
end
Mathieu NOE on 30 Nov 2021
hello
we can better hep you if you could supply the data (csv) file as well

Prachi Kulkarni on 3 Dec 2021
Hi,
Here is a slight modification of your code that can help.
Hi,
Here is a slight modification of your code that can help.
data_path = 'Data\';
file_name = 'Arpan_BINOCULAR-20200119-fft-0.csv';
file_path = strcat(data_path,file_name);
rows = size(data_i, 1);
all_rows_longitudes = zeros(rows,1); % Modified
all_rows_latitudes = zeros(rows,1); % Modified
all_rows_peak_velocities = zeros(rows,1); % Modified
all_rows_peak_velocities_errors = zeros(rows,1); % Modified
all_rows_intensities = zeros(rows,1); % Modified
for row = 1:rows
data = data_i(row, :); % Modified
RA_H = data(4);
RA_M = data(5);
RA_S = data(6);
Div1 = cos(DEC)*sin(RA-RA_NGP);
Div2 = cos(DEC_NGP)*sin(DEC)-sin(DEC_NGP)*cos(DEC)*cos(RA-RA_NGP);
l = l_NCP - atan2(Div1, Div2);
if longitude < 0
longitude = longitude + 360;
end
if ((longitude >= 0) && (longitude <= 90) || (longitude >=270) && (longitude <= 360)) && ((latitude >= -20) && (latitude <= 20))
x_data = (1:8192);
y_data = data(:, 10:end);
linear_y = 10.^(T./10);
frequency_rest = data(:, 7);
x_frequency = linspace(frequency_rest-1.25, frequency_rest+1.25, 8192);
x_1 = x_frequency(1500);
x_2 = x_frequency(6500);
y_1 = linear_y(1500);
y_2 = linear_y(6500);
m = ((y_1-y_2)/(x_1-x_2));
c = y_1 - m*x_1;
y_fit = m.*x_frequency + c;
y_fitted = linear_y-y_fit;
y_focussed = y_fitted(condition);
y_smooth = smooth(radial_vel_focussed, y_focussed, 0.1, 'rloess');
y_smooth = y_smooth(order);
[pks, locs, w, p] = findpeaks(y_smooth, radial_vel_focussed, 'MinPeakProminence', 0.02e-10);
peak_velocity = max(locs);
peak_data = [pks, locs', w', p];
if isempty(peak_data)
peak_data = zeros(1,4)
peak_velocity = 0
end
[a b] = find(peak_data == peak_velocity);
rightmost_peak_data = peak_data(a, :);
rightmost_pks = rightmost_peak_data(1);
rightmost_locs = rightmost_peak_data(2);
rightmost_w = rightmost_peak_data(3);
rightmost_p = rightmost_peak_data(4);
all_rows_latitudes(row) = latitude;
all_rows_longitudes(row) = longitude;
all_rows_peak_velocities(row) = peak_velocity;
all_rows_peak_velocities_errors(row) = rightmost_w;
all_rows_intensities(row) = rightmost_w*rightmost_p;
end
end

### Categories

Find more on Programming in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!