data interpolation and arrangement
Afficher commentaires plus anciens
I have csv file named as '1_1.csv', '1_2.csv', ...'1_41'.csv, '2_1.csv', '2_2.csv', ..'2_41.csv',............'71_1.csv', '71_2.csv',......'71_41.csv'. Each csv file has a data of temperature for different location (X ,Y, Z ,T). Each csv file has different number of rows because result is generated from comsol. I want to estimate temperature on specific point in each csv file. I have made another folder named "DATA" which contains my specific point(X, Y ,Z) in which i want to estimate temperature in each csv file. It is possible that our specific point may not be in csv file so i need to find temperature on that point with the help of interpolation.
I was using the code given below to get my temperature profile.
XYZq = csvread("DATA.csv");
num1s = 1:71;
num2s = 1:41;
T_interp = nan(size(XYZq,1),numel(num1s),numel(num2s)) % 3 dimensions
for num1 = num1s
for num2 = num2s
dataFilename = sprintf("%d_%d.csv",num1,num2)
data = csvread(dataFilename,9)
T_data = scatteredInterpolant(data(:,1:3),data(:,4));
T_interp(:,num1,num2) = T_data(XYZq);
end
end
now file name changes as '1_1_1.csv', '1_1_2.csv', ...'1_1_11'.csv, '1_2_1.csv', '1_2_2.csv', ..'1_2_11.csv',............'1_9_11.csv', '21_1_1.csv', '21_1_2.csv',.. '21_1_11.csv', '21_2_1.csv', '21_2_2.csv', '21_2_11.csv'.......'21_9_1.csv', '21_9_2.csv', .... '21_9_11.csv'.
now how can i modify this code to upload my csv file and get my desire temperature data? Please help me
Réponses (1)
Hi!
I understand that you currently have CSV files named in the format "x_y.csv", where x ranges from 1 to 71 and y ranges from 1 to 41. You also have a file named "DATA" containing (X, Y, Z) coordinates, and you want to find the corresponding temperature (T) for each (X, Y, Z) point.
Now, it seems that the issue you are facing is that the file names have been changed to the format "x_y_z.csv", with x ranging from 1 to 21, y ranging from 1 to 9, and z ranging from 1 to 11. However, you want to ensure that this new file naming format does not affect the behaviour of your existing code.
Assuming that only the file names have changed, and the content format of the files remains the same, the modification you need to make is to change the way the file names are generated. You can refer to the following code to incorporate the modification needed:
num1s = 1:21; % Range of values for the first number in the file name
num2s = 1:9; % Range of values for the second number in the file name
num3s = 1:11; % Range of values for the third number in the file name
for num1 = num1s
for num2 = num2s
for num3 = num3s
dataFilename = sprintf("%d_%d_%d.csv", num1, num2, num3);
disp(dataFilename); % Display the generated file name
end
end
end
By updating the file name generation in your code to match the new format, you should be able to process the files and get the desired result without changing any other line in the existing code.
Hope this helps.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!