Basic 2D-contour plot

2 views (last 30 days)
Moritz Schäfle
Moritz Schäfle on 1 Aug 2022
Commented: Star Strider on 9 Aug 2022
Hello everyone,
I am very new to Matlab and want to use it for a very basic data visualisation. I found some examples about 2D-contour plots, but no example worked for me and sometimes I had difficulties understanding certain functions.
I have a data file, which contains coordinates in x- and y-direction (first row and first column of an excel sheet). For every given position of these x- and y-coordinates there is a value.
There are plots that look very similar to what I aim for in the end:
My problem is, that getting the data out of my excel-file seems complicated and I don't know how to assign the coordinates to the values in Matlab.
I have currently a visualisation, but this one is based on Excel and does not fit certain optical requirements:
Also the interpolation of data between measured values is not very well done.
I am very glad about every answer that helps!
Best regards
Moritz

Answers (1)

Star Strider
Star Strider on 1 Aug 2022
Edited: Star Strider on 1 Aug 2022
One optiono is to use the first column and first row as the appropriate coordinate vectors, and then the rest of the matrix as the array to use with contourf.
I am not certain what result you want.
One possibility —
Data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1084750/data.xlsx')
Data = 11×53
NaN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 153 158 434 372 336 322 241 266 227 213 229 237 248 241 213 236 219 222 258 236 216 282 346 390 349 288 286 352 306 1 131 258 452 417 386 349 368 286 245 221 252 213 224 227 210 248 196 234 256 243 248 336 345 221 325 322 336 322 342 2 137 438 413 425 409 382 346 264 239 224 215 219 203 222 258 214 221 229 229 316 214 279 244 237 319 339 314 390 222 3 139 141 382 417 375 352 311 343 258 262 213 214 210 209 215 217 227 195 264 275 250 243 286 313 306 279 336 286 288 4 132 134 471 425 385 379 351 325 252 250 227 219 219 224 221 245 264 212 196 286 229 271 365 342 266 271 316 314 282 5 150 136 425 412 461 361 345 296 256 218 195 221 206 210 216 213 224 206 222 246 243 210 331 375 365 286 325 328 293 6 142 132 425 393 355 379 346 301 330 226 206 237 209 213 206 279 284 232 205 250 216 224 277 235 368 317 284 311 319 7 138 129 413 417 375 355 333 339 239 224 232 210 234 220 211 243 224 242 230 266 213 209 311 246 314 336 346 279 266 8 149 143 355 413 382 348 339 325 227 230 234 237 260 213 212 237 245 232 250 216 224 349 248 327 325 370 330 248 375
xv = Data(1,2:end);
yv = Data(2:end,1).';
Cm = Data(2:end, 2:end);
figure
contourf(xv, yv, Cm)
colormap(jet)
colorbar
xlabel('X')
ylabel('Y')
EDIT — (1 Aug 2022 at 14:23)
Added the specific colormap and the colorbar call.
.
  2 Comments
Star Strider
Star Strider on 9 Aug 2022
My pleasure!

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!