Use of interp2 in an arbitrary dataset (2024)

11 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Stathis Tingas am 27 Jan. 2024

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset

Bearbeitet: Stathis Tingas am 28 Jan. 2024

In MATLAB Online öffnen

Hello,

I would appreciate any help on the following issue.

I have a small dataset (3x3 matrix) which descirbes a mechanical property (say Z) in 2d space. Each line describes the mechanical property in the 2d space, hence I basically have 3 values of Z in the 2d space. Column 1 has the x-coordinate, column 2 has the y-coordinate and column 3 the respective value for Z.

For the sake of an example, my data looks like this:

X Y Z

0.25 0.25 0.5

0.50 0.60 1.5

0.75 0.35 3.0

I want to interpolate (between the given values) and extrapolate (from 0 up to 1 for both X and Y), ideally using spline, cubic or makima.

My plan was to use the following code:

x=[0.25;0.50;0.75];

y=[0.25;0.60;0.35];

[X,Y] = meshgrid(x,y);

Z = [0.5; 1.5; 3.0];

[Xq,Yq] = meshgrid(0:.01:1, 0:.01:1);

Zq = interp2(X,Y,Z,Xq,Yq,'spline');

However, when I try that, I get the following error:

Error using griddedInterpolant

Interpolation requires at least two sample points for each grid dimension.

Error in interp2>makegriddedinterp (line 226)

F = griddedInterpolant(varargin{:});

Error in interp2 (line 134)

F = makegriddedinterp(X, Y, V, method,extrap);

Could anyone advise?

Thanks

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Antworten (2)

Walter Roberson am 27 Jan. 2024

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#answer_1398476

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#answer_1398476

In MATLAB Online öffnen

x=[0.25;0.50;0.75];

y=[0.25;0.60;0.35];

Z = [0.5; 1.5; 3.0];

[Xq,Yq] = meshgrid(0:.01:1, 0:.01:1);

F = scatteredInterpolant(x, y, Z);

Zq = F(Xq, Yq);

surf(Xq, Yq, Zq)

Use of interp2 in an arbitrary dataset (3)

4 Kommentare

2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden

Stathis Tingas am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044546

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044546

Bearbeitet: Stathis Tingas am 28 Jan. 2024

Dear @Walter Roberson

Thank you for your response but to my understanding, scatteredInterpolant does not allow the use of spline, cubic or makima functions? Am I right? If so, is there a workaround to use particularly spline or makima?

Thanks

Stathis

William Rose am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044566

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044566

@Stathis Tingas,

You have 3 data points, on a 2D surface. That is the minimum number needed to define a plane (assuming they are not collinear). With so few points, you cannot estimate a more sophisticated surface, such as a spline. You would need at least 4 points (2 in each dimension) to use makima and at least 16 (4 in each dimension) to use spline. With only three points, linear interpolation is your only option.

Stathis Tingas am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044571

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044571

Bearbeitet: Stathis Tingas am 28 Jan. 2024

Thank you @William Rose for your response. I wasnt actually aware of this requirement for spline and makima.

My dataset will generally be small but it will vary from 3 up to 11-12 points. You are saying that makima would need 4 points. Therefore, if the original dataset as an example has the following 4 points, how could I use makima or cubic?

x=[0.25;0.50;0.75;0.9];

y=[0.25;0.60;0.35; 0.7];

Z = [0.5; 1.5; 3.0; 3.5];

Thanks

Torsten am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044586

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044586

Bearbeitet: Torsten am 27 Jan. 2024

In MATLAB Online öffnen

If your data are not gridded, you will have to live with "ScatteredInterpolant" and its interpolation methods.

And your four points in 2d constitute a curve. So Z could be interpolated on this curve maybe, but it makes little sense to treat them as sufficient to interpolate on a real two-dimensional rectangle.

x=[0.25;0.50;0.75;0.9];

y=[0.25;0.60;0.35; 0.7];

Z = [0.5; 1.5; 3.0; 3.5];

plot3(x,y,Z)

grid on

Use of interp2 in an arbitrary dataset (8)

Melden Sie sich an, um zu kommentieren.

Sulaymon Eshkabilov am 27 Jan. 2024

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#answer_1398481

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#answer_1398481

In MATLAB Online öffnen

Is this what you wanted to obtain:

% Given DATA:

Data = [ 0.25 0.25 0.5;

0.50 0.60 1.5;

0.75 0.75 3.0];

% Extract x, y, and z from Data

x = Data(:, 1);

y = Data(:, 2);

z = Data(:, 3);

[X,Y]=meshgrid(x,y);

Z = meshgrid(z);

% Interpolate using griddata

[Xq,Yq] = meshgrid(0:.01:1);

Zq = interp2(X,Y,Z,Xq,Yq,'spline');

% Plot the results

figure;

scatter3(x, y, z, 'ro', 'filled'); % Original data points in red

hold on;

surf(Xq, Yq, Zq, 'EdgeColor', 'none', 'FaceAlpha', 0.5); % Interpolated/extrapolated surface

xlabel('X');

ylabel('Y');

zlabel('Z(X,Y)');

title('Interpolation and Extrapolation of Mechanical Property');

Use of interp2 in an arbitrary dataset (10)

2 Kommentare

Keine anzeigenKeine ausblenden

Torsten am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044591

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044591

Bearbeitet: Torsten am 27 Jan. 2024

@Sulaymon Eshkabilov

You already interpolate (extrapolate) when you assume that (x,y,z) can be extended to (X,Y,Z) as existing database for interpolation with interp2.

Stathis Tingas am 27 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044606

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075161-use-of-interp2-in-an-arbitrary-dataset#comment_3044606

Bearbeitet: Stathis Tingas am 27 Jan. 2024

Dear @Sulaymon Eshkabilov, thanks for your response which seems to work fine but you have made a mistake in your Data matrix and this seems to make a difference.

In particular, the 3rd element in the y vector should be 0.35 and not 0.75.

When I try to use 0.35 with your version of the code, I get:

Error using griddedInterpolant

Sample points must be sorted in ascending order.

Error in interp2>makegriddedinterp (line 226)

F = griddedInterpolant(varargin{:});

Error in interp2 (line 134)

F = makegriddedinterp(X, Y, V, method,extrap);

Is there a workaround for this error?

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABMathematicsInterpolation

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Tags

  • interp2
  • 2d
  • makegriddedinterp
  • griddedinterpolant

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Use of interp2 in an arbitrary dataset (13)

Use of interp2 in an arbitrary dataset (14)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Use of interp2 in an arbitrary dataset (2024)
Top Articles
Vegane "Kinder Pingui" selber machen (Rezept mit Varianten)
EIN KLEINER TRAUM WIRD WAHR! Süßes Blütenfest mit himmlisch zarten FLOWER COOKIES & dem schönsten Sommerkleid
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Pizza Hut In Dinuba
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Free Online Games on CrazyGames | Play Now!
Sizewise Stat Login
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Jet Ski Rental Conneaut Lake Pa
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
C&T Wok Menu - Morrisville, NC Restaurant
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Dashboard Unt
Access a Shared Resource | Computing for Arts + Sciences
Speechwire Login
Healthy Kaiserpermanente Org Sign On
Restored Republic
3473372961
Craigslist Gigs Norfolk
Moxfield Deck Builder
Senior Houses For Sale Near Me
Whitehall Preparatory And Fitness Academy Calendar
Jail View Sumter
Nancy Pazelt Obituary
Birmingham City Schools Clever Login
Thotsbook Com
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5509

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.