Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I apply a function 360 times to a number of rows of data using a loop (or other method)?

1 次查看(过去 30 天)
I have an excel sheet with columns of (1) latitude, (2) longitude, (3) range (m), (4) depth (m) and (5) transect number (1:360). Each transect has 1016 rows. I wish to apply a function (weston_function below) to all rows of each transect (starting with 1 and finishing with 360). It would be useful for the function to also output the transect number for each row as well as the values for R, H, Transmission Loss (TL) at each row.
Currently I have this as my code but I am aware this does not work...
if true
% Input xlsx file for data
data = xlsread('Outputs_360Transects_20180627.xlsx',1);
% Input data required by function
R = data(:, 3); % Range (m)
H = data(:,4); % Depth (m)
T = 15.; % Temperature
S = 37.; % Salinity
c_sed = 1800;
rho_sed = 2.0;
attn = 0.6;
freq_Hz = 10000.;
% Run function 360 times
n = 1:360;
for i = 1:n
[R,H,TL, Transect] = weston_function(R, H, T, S, c_sed, rho_sed, attn, freq_Hz);
end
  3 个评论
Charlotte Findlay
Charlotte Findlay 2018-6-27
Hi Guillaume,
I wish to pass all rows of R and H (1016x1) of each transect i (of which there are 360) to the weston_function and get a vector output of R, H, TL and Transect Number for each row.
Guillaume
Guillaume 2018-6-27
How does the weston_function know what Transect number to return? Is that function actually written yet? If it is already written can you show its code?
Calling the weston_function for each transect is very easily done if you load your data into a table using readtable instead of xlsread. It's then just a call to rowfun. Exact syntax depends on the answers to the above.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by