Integrating double array to cell array

Hi everybody, i'm trying to integrate/put in a double array of the size 16x16 to a cell array with the size 16x16. For example i want the value of the double array from (1,1) in the cell array on {1,1}.speed. Further down is my code so far. In the last lines i extract data from the cell array to a double array. What i want to do is to tourn this around, integrate the top_plate_speed into the top_plate cell array. After this i want to have in every element of the cell array the values of position_x, position_y and speed.
Code:
radius_bottom = 0.125; %[m]
speed_bottom = 200; %[U/min]
position_upper_x = 0; %[m]
position_upper_y = 0; %[m]
square_length_upper = 0.06; %[m]
speed_top = 100; %[1/min]
contourf_accuracy = 10; %Number of different fields in the figure
%%Convert Parameters
speed_bottom = speed_bottom/60; %convert from [U/min] to [U/sec]
speed_top = speed_top/60; %convert from [U/min] to [U/sec]
%%Calculation
top_plate = cell(accurancy*square_length_upper+1,accurancy*square_length_upper+1);
for run_y = 1:size(top_plate,1)
for run_x = 1:size(top_plate,2)
top_plate{run_y,run_x}.position_x = (-(size(top_plate,2)-((size(top_plate,2)-1)/2))+run_x)/accurancy;
top_plate{run_y,run_x}.position_y = ((size(top_plate,1)-((size(top_plate,2)-1)/2))-run_y)/accurancy;
end
end
top_plate_speed_x = cellfun(@(x) x.position_x,top_plate);
top_plate_speed_y = cellfun(@(x) x.position_y,top_plate);
top_plate_speed = 2*pi*speed_top*sqrt(top_plate_speed_x.^2+top_plate_speed_y.^2);
I hope i described it understandable. Thanks in advance

 Accepted Answer

I cannot run your code, since I do not have all your variables.
If you want to convert your numeric matrix to a cell array, use the num2cell (link) function.

2 Comments

Sorry i forgot one variable. Here is the working code:
%%Calculation Parameters
accurancy = 250; %[Points per m]
rotation_accurancy = 5; %[Degrees per iteration] Must be a multiple of 360
radius_bottom = 0.125; %[m]
speed_bottom = 200; %[U/min]
position_upper_x = 0; %[m]
position_upper_y = 0; %[m]
square_length_upper = 0.06; %[m]
speed_top = 100; %[1/min]
contourf_accuracy = 10; %Number of different fields in the figure
%%Convert Parameters
speed_bottom = speed_bottom/60; %convert from [U/min] to [U/sec]
speed_top = speed_top/60; %convert from [U/min] to [U/sec]
%%Calculation
top_plate = cell(accurancy*square_length_upper+1,accurancy*square_length_upper+1);
for run_y = 1:size(top_plate,1)
for run_x = 1:size(top_plate,2)
top_plate{run_y,run_x}.position_x = (-(size(top_plate,2)-((size(top_plate,2)-1)/2))+run_x)/accurancy;
top_plate{run_y,run_x}.position_y = ((size(top_plate,1)-((size(top_plate,2)-1)/2))-run_y)/accurancy;
end
end
top_plate_speed_x = cellfun(@(x) x.position_x,top_plate);
top_plate_speed_y = cellfun(@(x) x.position_y,top_plate);
top_plate_speed = 2*pi*speed_top*sqrt(top_plate_speed_x.^2+top_plate_speed_y.^2);
I want to integrate the double array top_plate_speed to the cell top_plate. But this without a for loop if this is possible. I tried it as well with the num2cell function but it couldn't solve my problem. Thanks for your help
‘I want to integrate the double array top_plate_speed to the cell top_plate.’
What do you intend by ‘integrate’? If you want to do numerical integration, use the trapz (previously quad) or similar functions.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!